import { Directory } from "@talosjs/fs";
const dir = new Directory("/path/to/project");
await dir.mkdir(); // recursive by default
const names = await dir.ls({ recursive: true });
const totalBytes = await dir.getSize();
// Navigate fluently
const srcDir = dir.cd("src", "components");
// Iterate only files matching a pattern
for await (const file of srcDir.getFiles({ recursive: true, pattern: /\.ts$/ })) {
console.log(file.getPath());
}
// Copy, move, clean up
await dir.cp("/path/to/copy", { overwrite: true });
if (await dir.isEmpty()) {
await dir.rm({ force: true });
}
// Watch for changes
const watcher = dir.watch((event, filename) => {
console.log(`${event}: ${filename}`);
}, { recursive: true });
// watcher.close();