Velo by Example: File System

The FileSystem module provides file and directory operations.

Include the filesystem module.

include "lang/filesystem.vel";

FileSystem fs = new FileSystem();

Read, write, and append to text files.

fs.write("file.txt", "Content");
str content = fs.read("file.txt");
fs.append("file.txt", "\nMore content");

Check file existence and type.

bool exists = fs.exists("file.txt");
bool isFile = fs.isFile("file.txt");
bool isDir = fs.isDir("directory");

Directory and file management operations.

fs.mkdir("new_dir");
array[str] files = fs.list(".");

fs.copy("source.txt", "dest.txt");
fs.move("old.txt", "new.txt");
fs.delete("file.txt");