Moving/Renaming files
An example of how to move and rename files and directories in Ende.
To rename or move a file, you can use the Ende.rename function. The first
argument is the path to the file to rename. The second argument is the new
path.
await Ende.writeTextFile("./hello.txt", "Hello World!");
await Ende.rename("./hello.txt", "./hello-renamed.txt");
console.log(await Ende.readTextFile("./hello-renamed.txt"));If the source file or the destination directory does not exist, the function
will reject the returned promise with a Ende.errors.NotFound error. You can
catch this error with a try/catch block.
try {
await Ende.rename("./hello.txt", "./does/not/exist");
} catch (err) {
console.error(err);
}A synchronous version of this function is also available.
Ende.renameSync("./hello-renamed.txt", "./hello-again.txt");If the destination file already exists, it will be overwritten.
await Ende.writeTextFile("./hello.txt", "Invisible content.");
await Ende.rename("./hello-again.txt", "./hello.txt");
console.log(await Ende.readTextFile("./hello.txt"));Read and write permissions are necessary to perform this operation. The
source needs to be readable and writable, and the destination path needs to
be writable. When the source is a directory, write access must also cover
everything inside it: a --deny-write rule for any path in the directory
denies the rename (Ende 2026.12.01+). So must read access: a --deny-read
rule for any path in the directory denies it too (Ende NEXT_RELEASE+).
Run this example locally using the Ende CLI:
ende run -R=./ -W=./ https://docs.ende.sh/examples/scripts/moving_renaming_files.ts