34 lines
989 B
Lua
34 lines
989 B
Lua
-- Showcase the calog fs library end to end inside a unique temp dir: create a
|
|
-- directory, write and append a file, read it back, stat it, list the dir, then
|
|
-- remove the file and directory so nothing is left behind.
|
|
-- Run: bin/calog examples/scripts/libraries/fs.lua
|
|
|
|
local dir = "/tmp/calogFsExample." .. cryptoUuid()
|
|
local file = dir .. "/notes.txt"
|
|
|
|
fsMkdir(dir)
|
|
calogPrint("dir exists after mkdir:", fsExists(dir))
|
|
|
|
fsWrite(file, "line one\n")
|
|
fsAppend(file, "line two\n")
|
|
calogPrint("file exists after write:", fsExists(file))
|
|
|
|
local contents = fsRead(file)
|
|
calogPrint("contents:", contents)
|
|
|
|
local info = fsStat(file)
|
|
calogPrint("size:", info.size)
|
|
calogPrint("isFile:", info.isFile)
|
|
calogPrint("isDir:", info.isDir)
|
|
|
|
local entries = fsList(dir)
|
|
calogPrint("entry count:", #entries)
|
|
calogPrint("first entry:", entries[1])
|
|
|
|
fsRemove(file)
|
|
calogPrint("file exists after remove:", fsExists(file))
|
|
|
|
fsRemove(dir)
|
|
calogPrint("dir exists after remove:", fsExists(dir))
|
|
|
|
calogExit(0)
|