我如何将chmod与Node.js一起使用 [英] How do I use chmod with Node.js

查看:91
本文介绍了我如何将chmod与Node.js一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将chmod与Node.js一起使用?

How do I use chmod with Node.js?

fs中有一个方法应该执行此操作,但是我不知道第二个参数是什么.

There is a method in the package fs, which should do this, but I don't know what it takes as the second argument.

fs.chmod(路径,模式,[回调])

异步chmod(2).除了可能的异常外,没有其他参数被赋予完成回调.

Asynchronous chmod(2). No arguments other than a possible exception are given to the completion callback.

fs.chmodSync(路径,模式)

同步chmod(2).

Synchronous chmod(2).

(来自 Node.js文档)

如果我做类似的事情

fs.chmodSync('test', 0755);

什么也没有发生(文件未更改为该模式).

nothing happens (the file isn't changed to that mode).

fs.chmodSync('test', '+x');

也不起作用.

我正在Windows机器上工作.

I'm working on a Windows machine btw.

推荐答案

根据其源代码和第203行:

function modeNum(m, def) {
  switch (typeof m) {
    case 'number': return m;
    case 'string': return parseInt(m, 8);
    default:
      if (def) {
        return modeNum(def);
      } else {
        return undefined;
      }
  }
}

它使用八进制数字或字符串.

it takes either an octal number or a string.

例如

fs.chmodSync('test', 0755);
fs.chmodSync('test', '755');

这不适用于您的情况,因为文件模式仅存在于* nix机器上.

It doesn't work in your case because the file modes only exist on *nix machines.

这篇关于我如何将chmod与Node.js一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆