Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

164 lines (93 sloc) 4.565 kb

file

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.

Methods

file.exists(filepath)

    Describe: File exists


file.isFile(filepath)

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


file.isPlaintextFile(filepath)

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


file.isUTF8EncodingFile(filepath)

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


file.suffix(filename, suffix)

    Describe: File suffix append

    Return: {*}

    Example:

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

file.isDir(filepath)

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


file.isDirname(filepath)

    Describe: Is dir format name


file.readJSON(filepath)

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


file.findPackageJSON

    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

    Example:

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

file.delete(filepath)

    Describe: Delete the specified filepath. Will delete files and folders recursively.


file.read(filepath [, 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

    Example:

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.

    Example:

    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
    })

Jump to Line
Something went wrong with that request. Please try again.