Yet another filesystem helper based on node's fs module. This library exports everything from node's fs module but with some extra helpers.
npm install fs-plus
fs = require 'fs-plus'
Returns the absolute path to the home directory.
Make the given path absolute by resolving it against the current working directory.
- String
relativePath
: The string representing the relative path. If the path is prefixed with '~', it will be expanded to the current user's home directory.
- String: The absolute path or the relative path if it's unable to determine its real path.
Normalize the given path treating a leading ~
segment as referring to the
home directory. This method does not query the filesystem.
- String
pathToNormalize
: The string containing the abnormal path. If the path is prefixed with '~', it will be expanded to the current user's home directory.
- String Returns a normalized path.
Convert an absolute path to tilde path on Linux and macOS: /Users/username/dev => ~/dev
- String
pathToTildify
: The string containing the full path.
- String Returns a tildified path.
Get path to store application specific data.
-
String Returns the absolute path or null if platform isn't supported
- macOS:
~/Library/Application Support/
- Windows:
%AppData%
- Linux:
/var/lib
- macOS:
Is the given path absolute?
- String
pathToCheck
: The relative or absolute path to check.
- Bolean Returns
true
if the path is absolute,false
otherwise.
Returns true
if a file or folder at the specified path exists.
Returns true
if the given path exists and is a directory.
Asynchronously checks that the given path exists and is a directory.
Returns true if the specified path exists and is a file.
Returns true
if the specified path is a symbolic link.
Calls back with true
if the specified path is a symbolic link.
Returns true
if the specified path is executable.
Returns the size of the specified path.
Returns an Array with the paths of the files and directories contained within the directory path. It is not recursive.
- String
rootPath
: The absolute path to the directory to list. - Array
extensions
: An array of extensions to filter the results by. If none are given, none are filtered (optional).
Asynchronously lists the files and directories in the given path. The listing is not recursive.
Get all paths under the given path.
- String
rootPath
The {String} path to start at.
- Array Returns an array of strings under the given path.
Moves the file or directory to the target synchronously.
Removes the file or directory at the given path synchronously.
Open, write, flush, and close a file, writing the given content synchronously. It also creates the necessary parent directories.
Open, write, flush, and close a file, writing the given content asynchronously. It also creates the necessary parent directories.
Copies the given path recursively and synchronously.
Create a directory at the specified path including any missing parent directories synchronously.
Create a directory at the specified path including any missing parent directories asynchronously.
Recursively walk the given path and execute the given functions synchronously.
- String
rootPath
: The string containing the directory to recurse into. - Function
onFile
: The function to execute on each file, receives a single argument the absolute path. - Function
onDirectory
: The function to execute on each directory, receives a single argument the absolute path (defaults to onFile). If this function returns a falsy value then the directory is not entered.
Public: Recursively walk the given path and execute the given functions asynchronously.
Hashes the contents of the given file.
- String
pathToDigest
: The string containing the absolute path.
- String Returns a string containing the MD5 hexadecimal hash.
Finds a relative path among the given array of paths.
- Array
loadPaths
: An array of absolute and relative paths to search. - String
pathToResolve
The string containing the path to resolve. - Array
extensions
An array of extensions to pass to {resolveExtensions} in which case pathToResolve should not contain an extension (optional).
Returns the absolute path of the file to be resolved if it's found and undefined otherwise.
Like .resolve
but uses node's modules paths as the load paths to
search.
Finds the first file in the given path which matches the extension in the order given.
- String
pathToResolve
: the string containing relative or absolute path of the file in question without the extension or '.'. - Array
extensions
: the ordered array of extensions to try.
Returns the absolute path of the file if it exists with any of the given extensions, otherwise it's undefined.
Returns true for extensions associated with compressed files.
Returns true for extensions associated with image files.
Returns true for extensions associated with pdf files.
Returns true for extensions associated with binary files.
Returns true for files named similarily to 'README'
Returns true for extensions associated with Markdown files.
Is the filesystem case insensitive?
Returns true
if case insensitive, false
otherwise.
Is the filesystem case sensitive?
Returns true
if case sensitive, false
otherwise.
Calls fs.statSync
, catching all exceptions raised. This method calls fs.statSyncNoException
when provided by the underlying fs
module (Electron < 3.0).
Returns fs.Stats
if the file exists, false
otherwise.
Calls fs.lstatSync
, catching all exceptions raised. This method calls fs.lstatSyncNoException
when provided by the underlying fs
module (Electron < 3.0).
Returns fs.Stats
if the file exists, false
otherwise.