该模块提供了一个文件系统API,用于处理路径,目录,文件,链接以及输入和输出流的构造。 它遵循 CommonJS Filesystem/A 提议。
Example
// Writes a simple text file
var fs = require('fs');
if (!fs.exists('test.txt')) {
var textStream = fs.open('test.txt', {
write: true,
binary: false
});
try {
textStream.write('Hello World!');
textStream.flush();
} finally {
textStream.close();
}
console.log('Wrote test.txt');
} else {
console.error('test.txt already exists.');
}
Functions
- absolute (path)
- base (path, ext)
- canonical (path)
- changeGroup (path, group)
- changeOwner (path, owner)
- changePermissions (path, permissions)
- changeWorkingDirectory (path)
- copy (from, to)
- copyTree (from, to)
- directory (path)
- exists (path)
- extension (path)
- group (path)
- hardLink (existing, link)
- isAbsolute (path)
- isDirectory (path)
- isFile (path)
- isLink (path)
- isReadable (path)
- isRelative (path)
- isWritable (path)
- iterate (path)
- join ()
- lastModified (path)
- list (path)
- listDirectoryTree (path)
- listTree (path)
- makeDirectory (path, permissions)
- makeTree (path)
- move (source, target)
- normal (path)
- open (path, options)
- openRaw (path, options)
- owner (path)
- path ()
- permissions (path)
- read (path, options)
- readLink (path)
- relative (source, target)
- remove (path)
- removeDirectory (path)
- removeTree (path)
- resolve (paths...)
- same (pathA, pathB)
- sameFilesystem (pathA, pathB)
- size (path)
- split (path)
- symbolicLink (existing, link)
- touch (path, mtime)
- workingDirectory ()
- write (path, content, options)