filemanagementsystemfornode
Version:
A file management system for node.js application making managements of files easier, all in one code, you can delete, move, etc, files all in one code, making ability to manage a system eg a application requiring transfering of files in folders easier
34 lines (27 loc) • 975 B
text/typescript
import { FileWrapper } from "./wrappers/FileWrapper";
const file = new FileWrapper("./testFolder/sample.txt");
file.errorOnFound = (error) => {
if (error.code === "ENOENT") {
file.sync().writeFile("Default content");
console.log(`📄 File created: ${file.getPath()}`);
}
};
file.addMethod("logPath", function () {
console.log("File is at:", this.getPath());
return this;
});
(async () => {
if (!file.syncExist() && file.errorOnFound) {
file.errorOnFound({ code: "ENOENT" } as NodeJS.ErrnoException);
}
file
.rename("renamed.txt")
.invokeMethod("logPath")
.move("./testFolder/moved")
.copy("./backup")
.append("\nMore content added.")
.delete();
console.log("📄 Compressed File Content:", file.getInfo());
console.log("📑 File Metadata:", file.getMetaInfo());
console.log("📂 Files in directory:", file.list());
})();