fs-utilities
v1.1.1
Published
utility module for interacting with the file system e.g. asynchronously retreiving list of folders
Downloads
23
Maintainers
Readme
Installation
$ npm install fs-utilities
Usage
var fs_utils = require('fs-utilities')
fs_utils.getSubfolders( __dirname, function ( err, folders ){
if( err ) throw err;
folders.forEach( folder, ... );
});
API Overview
checkIfIsDirectory( directoryPath, callback )
Asynchronously tests if the specified file is a directory.
Arguments
directoryPath
- fullpath to file which should be testedcallback(err, directoryPath)
- will be executed after test finished. IfdirectoryPath
is not a folder, second callback argument will be undefined.
Example
fs_utils.checkIfIsDirectory( "fullFilePath" , function ( err, directory ){
if( err ) {
// "fullFilePath" is not a directory
} else {
console.log( "'" + directory + "' is a directory" );
}
});
checkIfIsDirectorySync( directoryPath )
Synchron function to test if the specified file is a directory.
Arguments
directoryPath
- fullpath to file which should be tested
Example
if( fs_utils.checkIfIsDirectorySync( "fullFilePath" ) ){
console.log( "'fullFilePath' is a directory" );
}
getSubfolders( directoryPath, callback )
Asynchron function which will pass an array containing all subfolders of the given directory to the also passed callback function.
Arguments
directoryPath
- path to look for subfolderscallback(err, subFolderList)
- will be executed after all subfolders have been detected. If case of an error, the search will be aborted and the second argument of the callback function will be undefined.
Example
fs_utils.getSubfolders( __dirname , function ( err, folders ){
if( err ) throw err;
console.log( "found following subfolders: " + folders );
});
getSubfoldersSync( directoryPath )
Synchronously generates and returns an array containing all subfolders of the given directory.
Arguments
directoryPath
- path to look for subfolders
Example
var folders = fs_utils.getSubfoldersSync( __dirname );
console.log( "found following subfolders: " + folders );
traverseAllSubFolders( directoryPath, callback, [opt_excludedDirectories, [opt_finishedCallback]] )
Asynchron function which will recursively traverse all subfolers.
Arguments
directoryPath
- path from where to start traversingcallback(subFolder)
- will be called for each traversedsubfolder
opt_excludedDirectories
- list of folders that will be skipedopt_finishedCallback
- function that is called after all subfolders have been traversed or an error occured
Example
function callForEachSubfolder( folder ){
console.log( "currently traversing folder '" + folder + "'" );
}
function callOnFinishedTraversing( err ){
if( err ) throw err;
console.log( "finished traversing all subfolders" );
}
var excludedFolders = ["excludedFolder0", "excludedFolder1", ...];
fs_utils.traverseAllSubFolders( __dirname,
callForEachSubfolder,
excludedFolders,
callOnFinishedTraversing );
traverseAllSubFoldersSync( directoryPath, callback, [opt_excludedDirectories] )
Synchronous function which will recursively traverse all subfolers.
Arguments
directoryPath
- path from where to start traversingcallback(subFolder)
- will be called for each traversed folderopt_excludedDirectories
- list of folders that will be skiped
Example
function callForEachSubfolder( folder ){
console.log( "currently traversing folder '" + folder + "'" );
}
var excludedFolders = ["excludedFolder0", "excludedFolder1", ...];
fs_utils.traverseAllSubFoldersSync( __dirname,
callForEachSubfolder,
excludedFolders );
console.log( "finished traversing all subfolders" );
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
Coverage
To run a code coverage analysis execute following commands:
$ npm install
$ npm run coverage
JSDoc
To generate a complete API documentation using JSDoc execute following commands:
$ npm install
$ npm run jsdoc