1 # fs plus [![Build Status](https://travis-ci.org/atom/fs-plus.svg?branch=master)](https://travis-ci.org/atom/fs-plus)
3 Yet another filesystem helper based on node's [fs](http://nodejs.org/api/fs.html)
4 module. This library exports everything from node's fs module but with some
14 fs = require 'fs-plus'
19 ### `getHomeDirectory()`
20 Returns the absolute path to the home directory.
22 ### `absolute(relativePath)`
23 Make the given path absolute by resolving it against the current
28 - **String** `relativePath`: The string representing the relative path. If the
29 path is prefixed with '~', it will be expanded to the current user's home
34 - **String**: The absolute path or the relative path if it's unable to
35 determine its real path.
37 ### `normalize(pathToNormalize)`
38 Normalize the given path treating a leading `~` segment as referring to the
39 home directory. This method does not query the filesystem.
43 - **String** `pathToNormalize`: The string containing the abnormal path. If the
44 path is prefixed with '~', it will be expanded to the current user's home
48 - **String** Returns a normalized path.
50 ### `getAppDataDirectory()`
51 Get path to store application specific data.
54 - **String** Returns the absolute path or null if platform isn't supported
56 - Mac: `~/Library/Application Support/`
60 ### `isAbsolute(pathToCheck)`
61 Is the given path absolute?
64 - **String** `pathToCheck`: The relative or absolute path to check.
67 - **Bolean** Returns `true` if the path is absolute, `false` otherwise.
69 ### `existsSync(pathToCheck)`
70 Returns `true` if a file or folder at the specified path exists.
72 ### `isDirectorySync(directoryPath)`
73 Returns `true` if the given path exists and is a directory.
75 ### `isDirectory(directoryPath)`
76 Asynchronously checks that the given path exists and is a directory.
78 ### `isFileSync(filePath)`
79 Returns true if the specified path exists and is a file.
81 ### `isSymbolicLinkSync(symlinkPath)`
82 Returns `true` if the specified path is a symbolic link.
84 ### `isSymbolicLink(symlinkPath, callback)`
85 Calls back with `true` if the specified path is a symbolic link.
87 ### `isExecutableSync(pathToCheck)`
88 Returns `true` if the specified path is executable.
90 ### `getSizeSync(pathToCheck)`
91 Returns the size of the specified path.
93 ### `listSync(rootPath, extensions)`
94 Returns an Array with the paths of the files and directories
95 contained within the directory path. It is not recursive.
98 - **String** `rootPath`: The absolute path to the directory to list.
99 - **Array** `extensions`: An array of extensions to filter the results by. If none are
100 given, none are filtered (optional).
102 ### `list(rootPath, extensions)`
103 Asynchronously lists the files and directories in the given path. The listing is not recursive.
105 ### `listTreeSync(rootPath)`
106 Get all paths under the given path.
109 - **String** `rootPath` The {String} path to start at.
112 - **Array** Returns an array of strings under the given path.
114 ### `moveSync(source, target)`
115 Moves the file or directory to the target synchronously.
117 ### `removeSync(pathToRemove)`
118 Removes the file or directory at the given path synchronously.
120 ### `writeFileSync(filePath, content, options)`
121 Open, write, flush, and close a file, writing the given content synchronously.
122 It also creates the necessary parent directories.
124 ### `writeFile(filePath, content, options, callback)`
125 Open, write, flush, and close a file, writing the given content
127 It also creates the necessary parent directories.
129 ### `copySync(sourcePath, destinationPath)`
130 Copies the given path recursively and synchronously.
132 ### `makeTreeSync(directoryPath)`
133 Create a directory at the specified path including any missing
134 parent directories synchronously.
136 ### `makeTree(directoryPath, callback)`
137 Create a directory at the specified path including any missing
138 parent directories asynchronously.
140 ### `traverseTreeSync(rootPath, onFile, onDirectory)`
141 Recursively walk the given path and execute the given functions
145 - **String** `rootPath`: The string containing the directory to recurse into.
146 - **Function** `onFile`: The function to execute on each file, receives a single argument
148 - **Function** `onDirectory`: The function to execute on each directory, receives a single
149 argument the absolute path (defaults to onFile). If this
150 function returns a falsy value then the directory is not
153 ### `traverseTree(rootPath, onFile, onDirectory, onDone)`
154 Public: Recursively walk the given path and execute the given functions
157 ### `md5ForPath(pathToDigest)`
158 Hashes the contents of the given file.
161 - **String** `pathToDigest`: The string containing the absolute path.
164 - **String** Returns a string containing the MD5 hexadecimal hash.
166 ### `resolve(loadPaths, pathToResolve, extensions)`
167 Finds a relative path among the given array of paths.
170 - **Array** `loadPaths`: An array of absolute and relative paths to search.
171 - **String** `pathToResolve` The string containing the path to resolve.
172 - **Array** `extensions` An array of extensions to pass to {resolveExtensions} in
173 which case pathToResolve should not contain an extension
177 Returns the absolute path of the file to be resolved if it's found and
180 ### `resolveOnLoadPath()`
181 Like `.resolve` but uses node's modules paths as the load paths to
184 ### `resolveExtension(pathToResolve, extensions)`
185 Finds the first file in the given path which matches the extension
189 - **String** `pathToResolve`: the string containing relative or absolute path of the
190 file in question without the extension or '.'.
191 - **Array** `extensions`: the ordered array of extensions to try.
194 Returns the absolute path of the file if it exists with any of the given
195 extensions, otherwise it's undefined.
197 ### `isCompressedExtension(ext)`
198 Returns true for extensions associated with compressed files.
200 ### `isImageExtension(ext)`
201 Returns true for extensions associated with image files.
203 ### `isPdfExtension(ext)`
204 Returns true for extensions associated with pdf files.
206 ### `isBinaryExtension(ext)`
207 Returns true for extensions associated with binary files.
209 ### `isReadmePath(readmePath)`
210 Returns true for files named similarily to 'README'
212 ### `isMarkdownExtension(ext)`
213 Returns true for extensions associated with Markdown files.
215 ### `isCaseInsensitive()`
216 Is the filesystem case insensitive?
217 Returns `true` if case insensitive, `false` otherwise.
219 ### `isCaseSensitive()`
220 Is the filesystem case sensitive?
221 Returns `true` if case sensitive, `false` otherwise.