Manage your files and folders quickly and easily.
When doing
write
,copy
,move
if the directory does not exist it will be created automatically.
All functions have their own version promises as well as synchronization.
import youfile from 'youfile'
const youfile = require('youfile')
You can create files with objects
as well as with other data such as fs.writeFile
.
youfile.write.file(path, 'data')
youfile.write.file(path, 'data', 'utf-8') // You can also add the encoding of the file in the format that will be created, (this is optional)
With objects
:
youfile.write.json(path, { data: true })
You can also define the amount of formatting spaces of 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 as an fs.readFile
:
youfile.read.file(path)
youfile.read.file(path, 'utf-8') // You can also add the encoding of the file in the format it will retranslate, (this is optional)
Returns the contents of the file in an object
:
youfile.read.json(path)
You can also read JSON files with comments:
youfile.read.json5(path)
Returns the sha256 of the file in a string
.
youfile.get.sha256(path)
Return an array
with all folders that are in the same directory.
youfile.get.folders(path)
Return an array
with all the files that are in the same directory.
youfile.get.files(path)
Returns an array
with all the files with a specified extension that are in the same directory
youfile.get.extFiles(path, '.ext')
Returns an array
with all folders contained in the directory
youfile.get.allFolders(path)
Returns an array
with all the files contained in the a directory.
youfile.get.allFiles(path)
Returns an array
with all the files with a specified extension contained in the directory
youfile.get.allExtFiles(path, '.ext')
Returns a boolean
if the file or directory exists
youfile.exists(path)
Removes files and directories
youfile.remove(path)
Remove files and directories if they exist
youfile.removeExists(path)
Copy files and directories
youfile.copy(path, dest)
I move files or directories
youfile.move(path, dest)