const filesystem = new VirtualFileSystem();
resolvePath(currentPath, targetPath)Resolves relative or absolute paths.
Parameters:
currentPath (string) - Current working directorytargetPath (string) - Target path (relative or absolute)Returns: Normalized absolute path
Examples:
filesystem.resolvePath('/home/user', 'documents')
// → '/home/user/documents'
filesystem.resolvePath('/home/user', '../parent')
// → '/home'
filesystem.resolvePath('/home/user', '~')
// → '/home/user'
filesystem.resolvePath('/home/user', '/absolute/path')
// → '/absolute/path'
exists(path)Check if path exists.
Returns: boolean
if (filesystem.exists('/home/user/README.txt')) {
// File exists
}
isDirectory(path)Check if path is a directory.
Returns: boolean
isFile(path)Check if path is a file.
Returns: boolean
list(path)List directory contents.
Parameters:
path (string) - Directory pathReturns: Array of {name: string, type: 'directory'|'file'} or null
Example:
const listing = filesystem.list('/home/user');
if (listing) {
listing.forEach(item => {
console.log(item.name, item.type);
});
}
createDirectory(path)Create directory and parent directories.
Parameters:
path (string) - Directory pathReturns: boolean - Success
readFile(path)Read file content.
Parameters:
path (string) - File pathReturns: File content (string) or null if not found
Example:
const content = filesystem.readFile('/home/user/README.txt');
if (content !== null) {
console.log(content);
}
writeFile(path, content)Write file content.
Parameters:
path (string) - File pathcontent (string) - File contentReturns: boolean - Success
Example:
filesystem.writeFile('/home/user/newfile.txt', 'Hello World');
remove(path)Remove file or directory.
Parameters:
path (string) - Path to removeReturns: boolean - Success
move(sourcePath, destPath)Move or rename file.
Parameters:
sourcePath (string) - Source pathdestPath (string) - Destination pathReturns: boolean - Success
/ - Root directory/home/user/ - User home directory/companies/ - Company records/achievements/ - Achievement logs/skills/ - Skills data/classified/ - Encrypted files/usr/bin/)Commands access filesystem via this.filesystem:
class MyApp {
constructor(terminal, filesystem, windowManager, os) {
this.filesystem = filesystem;
this.os = os; // Access currentPath via this.os.currentPath
}
async run(args) {
const path = args[0] || this.os.currentPath;
const resolvedPath = this.filesystem.resolvePath(this.os.currentPath, path);
if (!this.filesystem.exists(resolvedPath)) {
this.terminal.write(`\x1b[1;31mPath not found\x1b[0m\r\n`);
return;
}
if (this.filesystem.isDirectory(resolvedPath)) {
const listing = this.filesystem.list(resolvedPath);
// Process directory
} else {
const content = this.filesystem.readFile(resolvedPath);
// Process file
}
}
}
Filesystem is populated by FileSystemLoader from Jekyll data:
/home/user/ files/companies/ directories/home/user/projects/ files