3.0.2 • Published 6 years ago
read-directory v3.0.2
read-directory
Read a directory of files.
Install
npm install --save read-directoryExamples
Async example:
var read = require('read-directory')
read('./files', function (err, contents) {
console.log(contents)
})Sync example:
var read = require('read-directory')
var contents = read.sync('./files')Using in the browser with browserify & budo
Use the included browserify transform module to convert calls to read.sync to the contents of the directory.
Note that to use the browserify transform you must use read.sync, and the path to the file directory can not be a variable.
File that will be browserified & transformed:
var path = require('path')
var read = require('read-directory')
var contents = read.sync(path.join(__dirname, 'files'))Browserify example:
browserify index.js -t read-directory -o bundle.jsbudo example:
budo index.js:bundle.js -- -t read-directoryAPI
readDirectory
Read the contents of a directory asynchronously
Parameters
dirString – The directory to readoptionsObjectoptions.fsObject – alternate fs implementation, optionaloptions.dirnamesBoolean – include or exclude subdirectory names in keys of returned objectoptions.encodingString – encoding of files, default: utf8options.filterString – glob pattern for filtering files, examples:*.md,*.cssoptions.ignoreString – glob pattern for ignoring filesoptions.ignoreArray – array of glob patterns for ignoring filesoptions.transformFunction – A function you can use to transform the contents of files after they are read
Examples
var read = require('read-directory')
read('./files', function (err, contents) {
console.log(contents)
})readDirectory.sync
Read the contents of a directory asynchronously
Parameters
dirString – The directory to readoptionsObjectoptions.fsObject – alternate fs implementation, optionaloptions.dirnamesBoolean – include or exclude subdirectory names in keys of returned objectoptions.encodingString – encoding of files, default: utf8options.filterString – glob pattern for filtering files, examples:*.md,*.cssoptions.ignoreString – glob pattern for ignoring filesoptions.ignoreArray – array of glob patterns for ignoring filesoptions.transformFunction – A function you can use to transform the contents of files after they are read
Examples
var read = require('read-directory')
var contents = read.sync('./files')