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

时间:2022-09-13 19:00:14

方法说明:

同步版本的chmod() ,该方法用来改写文件的读写权限。

语法:

fs.chmodSync(path, mode)

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

接收参数:

1. path        文件路径

2. mode      读写权限(如:777)

例子:

 

复制代码 代码如下:

var fs = require('fs'),
 oldFilename = "./processId.txt";
fs.chmodSync(oldFilename, 777);

 

源码:

 

复制代码 代码如下:

fs.chmodSync = function(path, mode) {
  nullCheck(path);
  return binding.chmod(pathModule._makeLong(path), modeNum(mode));
};