simple-fs-tools
v1.0.0
Published
Use FS (FileSystem) easy in your project
Readme
Simple FS Tools
by PilotTim136
Description
This package provides simple file management functions that make reading, writing, appending, deleting files and folders, and checking their existence easier.
Functions
Below are all available functions and their purposes.
read(file: string)
Reads the content of a file.
Parameters:file- The filename or path.
Returns:- Returns the content of the file as a
string, orfalseon error.
save(fileName: string, fileContent: string)
Saves data to a file.
Parameters:fileName- The name or path of the file.fileContent- The content to be saved.
Returns:- Returns
trueif saving was successful, otherwisefalse.
append(fileName: string, fileContent: string)
Appends data to the end of a file.
Parameters:fileName- The name or path of the file.fileContent- The content to be appended.
Returns:- Returns
trueif appending was successful, otherwisefalse.
createFolder(folderName: string)
Creates a new folder.
Parameters:folderName- The name of the folder to be created.
Returns:- Returns
trueif the folder was successfully created, otherwisefalse.
exists(name: string)
Checks if a file or folder exists.
Parameters:name- The name or path of the file or folder.
Returns:- Returns
trueif the file or folder exists, otherwisefalse.
deleteStuff(name: string, forceDelete: boolean = false)
Deletes a file or folder.
Parameters:name- The name or path of the file or folder.forceDelete- Optional parameter. Forces deletion without prompt (trueorfalse). Default isfalse.
Returns:- Returns
trueif deletion was successful, otherwisefalse.
Installation
Run the following command to install the package:
npm install file-utility-toolsExample usage:
const file = require('simple-fs-tools');
// Example: Reading a file
const content = file.read('example.txt');
console.log(content);
// Example: Saving to a file
const success = file.save('example.txt', 'New Content');
console.log(success ? 'Saved!' : 'Save failed.');
// Example: Creating a new folder
const folderCreated = file.createFolder('newFolder');
console.log(folderCreated ? 'Folder created!' : 'Folder creation failed.');Lisense
ISC
