
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
folder-sync
Advanced tools
Provides a class which synchronously takes a snapshot of a directory and its contents.
Provides a class which synchronously takes a snapshot of a directory and its contents.
Usage:
var Folder = require('folder-sync');
var folder = new Folder('/path/to/directory');
var readme = folder.findFile('README.md');
readme.write('This is my readme!');
readme.read(); // => "This is my readme!"
readme.isFile; // => true
npm install folder-sync --save-dev
I DON'T recommend using this module on a web-facing environment. This is because everything in this module is done synchronously, meaning it's a blocking process. I primarily use it for Grunt tasks.
Creation:
var folder = new Folder('/path/to/directory');
A Folder
represents contents of a directory on the file system. It does not update itself - it's just a snapshot.
folder.files
An array of Item
objects, which represent the files in the folder. This does not include dot-files.
folder.folders
An array of Item
objects, which represent the folders in the folder. This does not include dot-files.
folder.dotFiles
An array of Item
objects, which represent the dot-files in the folder.
folder.dotFolders
An array of Item
objects, which represent the dot-folders in the folder.
folder.allFiles
An array of Item
objects, which represent all files in the folder (dot-files included).
folder.allFolders
An array of Item
objects, which represent all folders in the folder (dot-folders included).
folder.findFile(name)
Searches the folder for a file with the given name
(e.g. myFile.txt), and returns an Item
object of that file. If not found, it returns null
.
folder.findFolder(name)
Same as above, but for folders instead of files.
folder.filterFiles(regexp [, group])
Returns an array of file Item
objects that contain the given pattern. By default, it won't return dot-files, but the optional group
argument can be dot
to only return dot-files, or all
to return any type of file.
folder.filterFolders(regexp [, group])
Same as above, but for folders instead of files.
item.name
The name of the item (e.g. myFile.txt)
item.dirname
The path to the item's parent directory (e.g. /path/to)
item.path
The entire path to the item (e.g. /path/to/myFile.txt)
item.bytes
The byte-size of the item.
item.bytesOnDisk
The number of bytes that the item takes up on the disk.
item.changed
An instance of Date
, which is the last time the item was changed in any way (contents, permissions, properties, etc.)
item.modified
An instance of Date
, which is the last time the item's contents were changed.
item.accessed
An instance of Date
, which is the last time the item was accessed in any way.
item.created
An instance of Date
, which is the time when the item was created.
item.isFile
Boolean. Whether or not the item is a file or not.
item.isDirectory
Boolean. Whether or not the item is a directory or not.
item.isFolder
Same as item.isDirectory
.
item.read()
Returns the text content of the file, as a string.
If the item is not a file, returns undefined
.
item.write(string)
Overwrites the file contents with string
, and returns true.
If the item is not a file, returns undefined
.
item.readFolder()
Returns an instance of Folder
which represents this item.
If the item is not a directory, returns undefined
.
FAQs
Provides a class which synchronously takes a snapshot of a directory and its contents.
The npm package folder-sync receives a total of 0 weekly downloads. As such, folder-sync popularity was classified as not popular.
We found that folder-sync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.