node.js中的fs.fchown方法使用说明


方法说明:

更改文件所有权(文件描述符)。

语法:

fs.fchown(fd, uid, gid, [callback(err)])

由于该方法属于fs模块,使用前需要引入fs模块(var fs= require(“fs”) )

接收参数:

fd 文件描述符

uid 用户ID

gid 群体身份 (指共享资源系统使用者的身份)

callback 回调 ,传递异常参数 err

例子:

fs.open('content.txt', 'a', function (err, fd) { 

 if (err) { 

  throw err; 

 } 

 fs.fchown(fd, uid, gid, function(err){ 

  if (err) { 

   throw err; 

  } 

  console.log('fchmod complete'); 

  fs.close(fd, function () { 

   console.log('Done'); 

  }); 

 }) 

});

源码:

fs.fchown = function(fd, uid, gid, callback) {

  binding.fchown(fd, uid, gid, makeCallback(callback));

};

node.js中的fs.fchownSync方法使用说明
方法说明:同步版的fchown()。语法:fs.fchownSync(fd,uid,gid)由于该方法属于fs模块,使用前需要引入fs模块(varfs=require(fs))接收参数:fd文件描述符uid用户IDg

node.js中的fs.rmdir方法使用说明
方法说明:以异步的方式删除文件目录。语法:fs.rmdir(path,[callback(err)])由于该方法属于fs模块,使用前需要引入fs模块(varfs=require(fs))接收参数:path目

node.js中的fs.rmdirSync方法使用说明
方法说明:同步版本的rmdir()。返回值为null或undefined则表示删除成功,否则将抛出异常。语法:fs.rmdirSync(path)由于该方法属于fs模块,使用前需要引入fs