发表日期: 2022-01-07 10:44:36 浏览次数:104
【博罗网站建设|博罗网站制作|博罗网站设计】网站开发-网站改版-网站维护-网站搭建-网站托管-网站费用-网站价格-网站多少钱-网站报价

以上代码执行结果如下:
$ node file.js 查看 /tmp 目录input.outoutput.outtest test.txt
以下为删除目录的语法格式:
fs.rmdir(path, callback)
参数使用说明如下:
path - 文件路径。
callback - 回调函数,没有参数。
接下来我们创建 file.js 文件,代码如下所示:
var fs = require("fs");// 执行前创建一个空的 /tmp/test 目录console.log("准备删除目录 /tmp/test");fs.rmdir("/tmp/test",function(err){
if (err) {
return console.error(err);
}
console.log("读取 /tmp 目录");
fs.readdir("/tmp/",function(err, files){
if (err) {
return console.error(err);
}
files.forEach( function (file){
console.log( file );
});
});});以上代码执行结果如下:
$ node file.js 准备删除目录 /tmp/test读取 /tmp 目录……
以下为 Node.js 文件模块相同的方法列表:
| 序号 | 方法 & 描述 |
|---|---|
| 1 | fs.rename(oldPath, newPath, callback) 异步 rename().回调函数没有参数,但可能抛出异常。 |
| 2 | fs.ftruncate(fd, len, callback) 异步 ftruncate().回调函数没有参数,但可能抛出异常。 |
| 3 | fs.ftruncateSync(fd, len) 同步 ftruncate() |
| 4 | fs.truncate(path, len, callback) 异步 truncate().回调函数没有参数,但可能抛出异常。 |
| 5 | fs.truncateSync(path, len) 同步 truncate() |
| 6 | fs.chown(path, uid, gid, callback) 异步 chown().回调函数没有参数,但可能抛出异常。 |
| 7 | fs.chownSync(path, uid, gid) 同步 chown() |
| 8 | fs.fchown(fd, uid, gid, callback) 异步 fchown().回调函数没有参数,但可能抛出异常。 |
| 9 | fs.fchownSync(fd, uid, gid) 同步 fchown() |
| 10 | fs.lchown(path, uid, gid, callback) 异步 lchown().回调函数没有参数,但可能抛出异常。 |
| 11 | fs.lchownSync(path, uid, gid) 同步 lchown() |
| 12 | fs.chmod(path, mode, callback) 异步 chmod().回调函数没有参数,但可能抛出异常。 |
| 13 | fs.chmodSync(path, mode) 同步 chmod(). |
| 14 | fs.fchmod(fd, mode, callback) 异步 fchmod().回调函数没有参数,但可能抛出异常。 |
| 15 | fs.fchmodSync(fd, mode) 同步 fchmod(). |
| 16 | fs.lchmod(path, mode, callback) 异步 lchmod().回调函数没有参数,但可能抛出异常。Only available on Mac OS X. |
| 17 | fs.lchmodSync(path, mode) 同步 lchmod(). |
| 18 | fs.stat(path, callback) 异步 stat(). 回调函数有两个参数 err, stats,stats 是 fs.Stats 对象。 |
| 19 | fs.lstat(path, callback) 异步 lstat(). 回调函数有两个参数 err, stats,stats 是 fs.Stats 对象。 |
| 20 | fs.fstat(fd, callback) 异步 fstat(). 回调函数有两个参数 err, stats,stats 是 fs.Stats 对象。 |
| 21 | fs.statSync(path) 同步 stat(). 返回 fs.Stats 的实例。 |
| 22 | fs.lstatSync(path) 同步 lstat(). 返回 fs.Stats 的实例。 |
| 23 | fs.fstatSync(fd) 同步 fstat(). 返回 fs.Stats 的实例。 |
| 24 | fs.link(srcpath, dstpath, callback) 异步 link().回调函数没有参数,但可能抛出异常。 |
| 25 | fs.linkSync(srcpath, dstpath) 同步 link(). |
| 26 | fs.symlink(srcpath, dstpath[, type], callback) 异步 symlink().回调函数没有参数,但可能抛出异常。 type 参数可以设置为 'dir', 'file', 或 'junction' (默认为 'file') 。 |
| 27 | fs.symlinkSync(srcpath, dstpath[, type]) 同步 symlink(). |
| 28 | fs.readlink(path, callback) 异步 readlink(). 回调函数有两个参数 err, linkString。 |
| 29 | fs.realpath(path[, cache], callback) 异步 realpath(). 回调函数有两个参数 err, resolvedPath。 |
| 30 | fs.realpathSync(path[, cache]) 同步 realpath()。返回绝对路径。 |
| 31 | fs.unlink(path, callback) 异步 unlink().回调函数没有参数,但可能抛出异常。 |
| 32 | fs.unlinkSync(path) 同步 unlink(). |
| 33 | fs.rmdir(path, callback) 异步 rmdir().回调函数没有参数,但可能抛出异常。 |
【博罗网站建设|博罗网站制作|博罗网站设计】网站开发-网站改版-网站维护-网站搭建-网站托管-网站费用-网站价格-网站多少钱-网站报价