Scripting · Filesystem
Filesystem operations.
Script land includes a small readable filesystem API without exposing arbitrary shell execution.
print(pwd())
if(!exists("work")) {
make_dir("work")
}
touch("work/input.txt")
copy("work/input.txt", "work/copy.txt")
move("work/copy.txt", "work/final.txt")
entries := ls("work")
print(entries.prettify())
cat("work/final.txt")
text := open("work/final.txt")
remove("work/final.txt") | Operation | Purpose |
|---|---|
pwd() | Return the current script working directory. |
cd(path) | Change directory under standalone run/sh hosts. |
exists(path) | Test whether a path exists. |
ls() / ls(path) | Return a deterministically filename-sorted array of directory entry names. |
cat(path) | Write the file contents exactly to stdout, without adding a trailing newline; returns null. |
make_dir(path) | Create the directory path, including missing parents. |
touch(path) | Create the file if needed or open it for append without replacing its contents. |
copy(from, to) | Copy a file, replacing an existing destination file. |
move(from, to) | Move/rename a path using the host filesystem operation. |
remove(path) | Remove a file. Directory removal is deliberately not recursive. |
open(path) | Load the entire file as a string. |
Build-hosted scripts remain confined by Nift's project/path rules. Standalone nift run and nift sh use the process working directory. open(path) is data access; it is intentionally distinct from template @input, script @import and source injection.
NextManaged files →