There are many functions related to software system operations. First of all, it can be divided into two categories.
One type is asynchronous callback. One type is synchronous.
Only the asynchronous ones are sorted here. For the synchronous ones, just add Sync after the function name
1. The first is the most common type of reading and writing functions. The function name and form should originate from the C language.
fs.open(file path , read and write identification, [file mode value, 666], callback function (err, file handle fd));
fs.read(file handle fd, written buffer, offset, length, position, callback function ( err, bytesRead, buffer)); " " Handle, callback function)
2. It is more convenient to read and write files directly.
Copy code
3. Other common file operations
Copy code
The code is as follows:
fs.stat (file path, callback function (err.fs.Stats object));/fs.fstat (File handle fd, callback function (err.fs.Stats object)); /fs.lstat (link path, callback function (err.fs.Stats object)); Path, access time, new time, callback function);/fs.futimes(file handle, access time, new time, callback function); (Stats of the current file, stats before change));
4. Directory operations
Copy code
The code is as follows:
fs.mkdir(path, permission mode/777, callback function);
fs.rmdir(path, callback function); fs.readdir(path, callback function (err, fileNameArray));
5. Link file operation
The code is as follows:
Create a link
fs.link(srcpath, dstpath, [callback])
fs.symlink(destination, path, [type], [callback])
The path pointed by the read link fs.readlink(path, [callback(err,linkstr)]) fs.unlink(path,[callback]);