Fetching contributors…
Cannot retrieve contributors at this time
164 lines (93 sloc) 4.46 KB


There are many provided methods for reading and writing files, traversing the filesystem and finding files by matching globbing patterns. Many of these methods are wrappers around built-in Node.js file functionality, but with additional error handling, logging and character encoding normalization.



    Describe: File exists


    Describe: Is the given path a file? Returns a boolean.


    Describe: Is the given path a plaintext file? Returns a boolean.


    Describe: Is the given path a UTF8 encoding file? Returns a boolean.

file.suffix(filename, suffix)

    Describe: File suffix append

    Return: {*}


```js file.suffiex("jquery.js", "min") // => jquery.min.js ```


    Describe: Is the given path a directory? Returns a boolean.


    Describe: Is dir format name


    Describe: Read a file from the filesystem and parse as JSON


    Describe: Looks for a project's package.json file. Walks up the directory tree untilit finds a package.json file or hits the root. Does not throw when nopackages.json is found, just returns null.

file.readPackageJSON( [dir] )

    Describe: Read a package.json file's contents, parsing the data as JSON and returning the result

file.listdir(dir, callback)

    Describe: List directories within a directory.

file.glob(pattern [, rootdir])

    Describe: Get the pattern matched files, default root dir is cwd

file.expand(patterns [, options])

    Describe: Return a unique array of all file or directory paths that match the given globbing pattern(s).

    Return: {array} matche files


```js file.expand(['!./foo/.css', './foo/']) ```


    Describe: Delete the specified filepath. Will delete files and folders recursively. [, encoding])

    Describe: Read and return a file's contents.

file.write(filepath, contents [, encoding])

    Describe: Write the specified contents to a file, creating intermediate directories if necessary

file.writeTemp(filepath, contents [, encoding])

    Describe: Write the specified contents to a temp file

file.copy(src, dest)

    Describe: Copy a source file or directory to a destination path, creating intermediate directories if necessary

file.find(dirpath, filename);

    Describe: Search for a filename in the given directory or all parent directories.

    Return: {string}

file.mkdir(dirpath [, mode])

    Describe: Given a path to a directory, create it, and all the intermediate directories as well


```js file.mkdir("/tmp/dir", 755) ```

file.mkdirTemp([dirname] [, mode])

    Describe: Create temp dir

    Return: {string}

file.walkdir(rootdir, callback)

    Describe: Recurse into a directory, executing callback for each file.


```js file.walkdir("/tmp", function(error, path, dirs, name) { // path is the current directory we're in // dirs is the list of directories below it // names is the list of files in it }) ```