recursive-readdir
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
minimatch | 3.1.2 | 11.66 kB | ISC | prod |
The recursive-readdir
npm package is designed to list all files in a directory and its subdirectories recursively. This means it digs down into every level of directories, picking up files along the way, but doesn't list the directories themselves. It's worth noting that because recursive-readdir
uses fs.readdir under the hood, the order of files inside the directories is not guaranteed.
To use recursive-readdir
in your JavaScript project, you'll first need to install the module. You do this by running npm install recursive-readdir
. Once installed, you can import it into your JavaScript file using var recursive = require("recursive-readdir")
.
You can then call the recursive
function providing the path of the directory you want to traverse as a string. The recursive
function takes a callback as the second argument, which receives error
and files
arguments. Here's an example:
var recursive = require("recursive-readdir");
recursive("some/path", function (err, files) {
console.log(files); // logs all files in 'some/path' directory and subdirectories
});
If there are certain files you want to ignore, you can pass these in as an array of strings as a second argument before the callback. For example:
var recursive = require("recursive-readdir");
recursive("some/path", ["foo.cs", "*.html"], function (err, files) {
console.log(files); // logs all files except ones named 'foo.cs' or ending in '.html'
});
If you prefer to use promises instead of callbacks, recursive-readdir
also supports this. You can simply omit the callback and a promise will be returned:
var recursive = require("recursive-readdir");
recursive("some/path").then(
function(files) {
console.log("files are", files);
},
function(error) {
console.error("something exploded", error);
}
);
The entire documentation for the recursive-readdir
package is found in its README on GitHub. This includes the package's details, information about installation, usage examples, and notes about its behavior. You can access the README directly on GitHub at git://github.com/jergason/recursive-readdir.git, where you'll find an extensive explanation of the package and its functionality.