tomo-koans/lesson-templates/lesson-13-paths.tm
2025-03-24 22:16:58 -04:00

48 lines
751 B
Tcl

# Paths
func main():
# Tomo includes a built-in literal type for file paths
# A path is inside parentheses and begins with `/`, `~`, `.` or `..`
file := (/tmp/test-file.txt)
>> file
= /tmp/test-file.txt
file:write("first line")
>> file:read()
= "???"
file:append("
second line
")
>> file:exists()
= yes
>> file:lines()
= [???]
# You can iterate over a file by lines:
>> upper_lines := [line:upper() for line in file:by_line()]
= [???]
>> file:parent()
= /???
>> file:extension()
= "???"
>> file:parent():child("other-file.txt")
= /???
>> dir := (/tmp/test-*.txt):glob()
= [???]
file:remove()
>> file:exists()
= ???