awtk/tests/fscripts/demo_fs.fs

71 lines
2.0 KiB
Forth
Raw Normal View History

2021-01-07 14:36:33 +08:00
assert(file_write("test.txt", "hello"))
assert(file_exist("test.txt"))
assert(file_get_size("test.txt")==5)
assert(file_read_text("test.txt") == "hello")
2021-09-09 15:04:54 +08:00
assert(file_write_append("test.txt","world"))
assert(file_read_text("test.txt") == "helloworld")
assert(file_rename("test.txt","rename.txt"))
2021-01-07 14:36:33 +08:00
assert(!file_exist("test.txt"))
2021-09-09 15:04:54 +08:00
assert(file_read_text("rename.txt") == "helloworld")
assert(file_copy("rename.txt","copy.txt"))
assert(file_read_text("copy.txt") == "helloworld")
assert(file_remove("copy.txt"))
assert(!file_exist("copy.txt"))
a = file_stat("rename.txt")
print(join(": ","dev",a.dev))
print(join(": ","ino",a.ino))
print(join(": ","mode",a.mode))
print(join(": ","nlink",a.nlink))
print(join(": ","uid",a.uid))
print(join(": ","rdev",a.rdev))
print(join(": ","size",a.size))
print(join(": ","atime",a.atime))
print(join(": ","mtime",a.mtime))
print(join(": ","ctime",a.ctime))
print(join(": ","is_dir",a.is_dir))
print(join(": ","is_link",a.is_link))
print(join(": ","is_reg_file",a.is_reg_file))
assert(file_remove("rename.txt"))
assert(!file_exist("rename.txt"))
2021-01-07 14:36:33 +08:00
assert(file_write("test.bin", "hello", 5))
assert(file_exist("test.bin"))
assert(file_get_size("test.bin")==5)
a = file_read_binary("test.bin")
assert(value_get_binary_size(a) == 5)
assert(file_remove("test.bin"))
assert(!file_exist("test.bin"))
assert(file_write("test.bin", a))
assert(file_exist("test.bin"))
assert(file_get_size("test.bin")==5)
assert(file_remove("test.bin"))
assert(path_create("a/b/c"))
assert(path_exist("a/b/c"))
assert(path_remove("a/b/c"))
assert(!path_exist("a/b/c"))
2021-09-09 15:04:54 +08:00
assert(path_rename("a/b","a/bbb"))
assert(!path_exist("a/b"))
assert(path_exist("a/bbb"))
assert(file_write("a/test.txt", "hello"))
a = path_list("a")
assert(a.size==2)
b = array_get(a,0)
c = array_get(a,1)
assert(b.name=="bbb")
assert(c.name=="test.txt")
assert(path_remove("a"))
assert(!path_exist("a"))
2021-01-07 14:36:33 +08:00
2021-09-09 15:04:54 +08:00
print(path_get_exe())
print(path_get_cwd())
2021-01-07 14:36:33 +08:00
print(path_get_temp())
print(path_get_app_root())
print(path_get_user_storage_root())
2021-09-09 15:04:54 +08:00
unset(a)
unset(b)
unset(c)