Skip to main content

File System Library Reference

The fs library provides functions for interacting with the file system: creating, reading, writing, moving, and inspecting files and directories. You must import the module before using:

import fs

Or import specific functions:

from fs import read, write, exists, getfiles

Available Functions

FunctionParametersDescription
append(filename, content)filename, content (Strings)Appends content (with newline) to the file.
copy(source, destination)source, destination (Strings)Copies a file from source to destination.
create(filename)filename (String)Creates a new empty file (overwrites if exists).
delete(filename)filename (String)Deletes the specified file.
exists(filename)filename (String)Returns true if the file exists, otherwise false.
move(source, destination)source, destination (Strings)Renames or moves a file.
read(filename)filename (String)Reads the entire file and returns its contents as a string.
write(filename, content)filename, content (Strings)Writes content to the file (overwrites existing).
filename(path)path (String)Returns only the file name portion of a path.
filepath(path)path (String)Returns the parent directory portion of a path.
folderexist(folder)folder (String)Returns true if the folder exists, otherwise false.
foldername(path)path (String)Returns only the folder name portion of a path.
folderpath(path)path (String)Returns the parent directory portion of a folder path.
getfileextension(filename)filename (String)Returns the extension of the file (without dot).
getfiles(folder)folder (String)Returns a list of file paths within folder.
getfolders(folder)folder (String)Returns a list of sub-folder paths within folder.
getlastmodifiedtime(filename)filename (String)Returns last-modified timestamp in seconds since UNIX epoch.
getparentdirectory(path)path (String)Returns the parent directory of the given path.
getfilesize(filename)filename (String)Returns the size of the file in bytes.
getsub(folder)folder (String)Alias for getfolders(folder).
makefolder(folder)folder (String)Creates a new folder (including parents) if it does not exist.
movefolder(source, destination)source, destination (Strings)Renames or moves a folder.
readcontent(filename)filename (String)Reads all lines of filename and returns them as a list of strings.
readline(filename, n)filename (String), n (Number)Returns the nth line (0‑indexed) of the file.
readline(filename, s, e)filename, s, e (Number)Returns lines from index s up to (but not including) e as a list of strings.

Examples

Note: Use set to assign values and always import fs.


1. append(filename, content)

import fs
set f to "notes.txt"
fs.create(f)
set _ to fs.append(f, "First line")
set _ to fs.append(f, "Second line")
set content to fs.read(f)
show(content)
// Output:
// First line
// Second line

2. copy(source, destination)

import fs
set src to "notes.txt"
set dst to "notes_copy.txt"
set _ to fs.copy(src, dst)
show(fs.read(dst))
// Output:
// First line
// Second line

3. create(filename)

import fs
set newfile to "empty.txt"
set _ to fs.create(newfile)
show(fs.exists(newfile))
// Output:
// true

4. delete(filename)

import fs
set todelete to "empty.txt"
set _ to fs.delete(todelete)
show(fs.exists(todelete))
// Output:
// false

5. exists(filename)

import fs
show(fs.exists("notes.txt"))
// Output:
// true

show(fs.exists("nonexistent.txt"))
// Output:
// false

6. move(source, destination)

import fs
set _ to fs.move("notes_copy.txt", "archived/notes_archive.txt")
show(fs.exists("archived/notes_archive.txt"))
// Output:
// true

7. read(filename)

import fs
set text to fs.read("notes.txt")
show(text)
// Output:
// First line
// Second line

8. write(filename, content)

import fs
set _ to fs.write("log.txt", "Log start")
show(fs.read("log.txt"))
// Output:
// Log start

9. filename(path)

import fs
set name to fs.filename("/home/user/docs/report.pdf")
show(name)
// Output:
// report.pdf

10. filepath(path)

import fs
set dir to fs.filepath("/home/user/docs/report.pdf")
show(dir)
// Output:
// /home/user/docs

11. folderexist(folder)

import fs
show(fs.folderexist("archived"))
// Output:
// true

show(fs.folderexist("missing_folder"))
// Output:
// false

12. foldername(path)

import fs
set fn to fs.foldername("/home/user/docs")
show(fn)
// Output:
// docs

13. folderpath(path)

import fs
set fp to fs.folderpath("/home/user/docs")
show(fp)
// Output:
// /home/user

14. getfileextension(filename)

import fs
show(fs.getfileextension("archive.tar.gz"))
// Output:
// gz

15. getfiles(folder)

import fs
set files to fs.getfiles("archived")
show(files)
// Output (example):
// ["archived/notes_archive.txt"]

16. getfolders(folder)

import fs
set dirs to fs.getfolders("/home/user")
show(dirs)
// Output (example):
// ["/home/user/docs", "/home/user/archived"]

17. getlastmodifiedtime(filename)

import fs
set t to fs.getlastmodifiedtime("notes.txt")
show(t)
// Output (example):
// 1713596107

18. getparentdirectory(path)

import fs
set pd to fs.getparentdirectory("/home/user/docs/report.pdf")
show(pd)
// Output:
// /home/user/docs

19. getfilesize(filename)

import fs
set size to fs.getfilesize("notes.txt")
show(size)
// Output (example):
// 25

20. getsub(folder)

import fs
set subs to fs.getsub("/home/user")
show(subs)
// Output (example):
// ["/home/user/docs", "/home/user/archived"]

21. makefolder(folder)

import fs
set _ to fs.makefolder("backup/2025")
show(fs.folderexist("backup/2025"))
// Output:
// true

22. movefolder(source, destination)

import fs
set _ to fs.movefolder("backup/2025", "backup/2025_old")
show(fs.folderexist("backup/2025_old"))
// Output:
// true

23. readcontent(filename)

import fs
set lines to fs.readcontent("notes.txt")
show(lines)
// Output:
// ["First line", "Second line"]

24. readline(filename, n)

import fs
set line0 to fs.readline("notes.txt", 0)
show(line0)
// Output:
// First line

set lines1to2 to fs.readline("notes.txt", 0, 2)
show(lines1to2)
// Output:
// ["First line", "Second line"]

Conclusion

The fs library in EasyBite gives you robust file and directory operations:

  • Import module: import fsfs.function(...)
  • Selective import: from fs import read, write, existsread("file"), write("file", content)

Use these functions to manage files and folders directly from your EasyBite scripts.