tomo-koans/lesson-templates/lesson-13-paths.tm

38 lines
579 B
Plaintext
Raw Permalink Normal View History

2025-03-24 19:16:58 -07:00
# Paths
func main():
# Tomo includes a built-in literal type for file paths
# A path is inside parentheses and begins with `/`, `~`, `.` or `..`
2025-03-24 23:25:54 -07:00
path := (/tmp/test-file.txt)
>> path
2025-03-25 14:28:48 -07:00
= (/tmp/test-file.txt)
2025-03-24 19:16:58 -07:00
2025-03-25 14:28:48 -07:00
path:write("first")
2025-03-24 23:25:54 -07:00
>> path:read()
2025-03-24 19:16:58 -07:00
= "???"
2025-03-25 14:28:48 -07:00
path:append(",second")
2025-03-24 19:16:58 -07:00
2025-03-24 23:25:54 -07:00
>> path:exists()
2025-03-24 19:16:58 -07:00
= yes
2025-03-24 23:25:54 -07:00
>> path:parent()
2025-03-25 14:28:48 -07:00
= (/???)
2025-03-24 19:16:58 -07:00
2025-03-24 23:25:54 -07:00
>> path:extension()
2025-03-24 19:16:58 -07:00
= "???"
2025-03-24 23:25:54 -07:00
>> path:parent():child("other-file.txt")
2025-04-01 23:10:21 -07:00
= (/???)
2025-03-24 19:16:58 -07:00
>> dir := (/tmp/test-*.txt):glob()
= [???]
2025-03-24 23:25:54 -07:00
path:remove()
2025-03-24 19:16:58 -07:00
2025-03-24 23:25:54 -07:00
>> path:exists()
2025-03-24 19:16:58 -07:00
= ???