Manage your files and folders quickly and easily
When doing
write
,copy
,move
if the directory does not exist it will be created automatically.
import youfile from "youfile";
const youfile = require("youfile");
You can create files with objects
as well as with strings
.
With strings
:
youfile.write.file(path, "data");
With objects
:
youfile.write.json(path, { data: true });
You can also define the amount of formatting spaces in the json file, default is 0.
youfile.write.json(path, { data: true }, 4);
If when creating the folder the directory does not exist, it will be created automatically.
youfile.write.dir(path);
Returns the contents of the file in a string
:
youfile.read.file(path);
Returns the contents of the file in an object
:
youfile.read.json(path);
You can also read files with comments:
youfile.read.json5(path);
Returns a promise
with the file's SHA-256 hash as a string
youfile.get.sha256(path);
Returns an array
of all folders in the same directory
youfile.get.folders(path);
Returns an array
of all files in the same directory
youfile.get.files(path);
Returns an array
of all folders within the directory
youfile.get.allFolders(path);
Returns an array
of all files within the directory
youfile.get.allFiles(path);
Returns an array
of all files with a specific extension in the same directory:
youfile.search.extnameFiles(path, ".ext");
Returns an array
of all files with a specific name in the same directory
youfile.search.nameFiles(path, "text.txt");
Returns an array
of all files with a specific extension in the directory
youfile.search.allExtnameFiles(path, ".ext");
Returns an array
of all files with a specific name in the directory
youfile.search.allNameFiles(path, "text.txt");
Returns a boolean
indicating whether the file or directory exists
youfile.exists(path);
Deletes files and directories
youfile.remove(path);
Deletes files and directories if they exist
youfile.removeExists(path);
Copies files and directories
youfile.copy(path, dest);
Moves files or directories
youfile.move(path, dest);