NodeJS - 将文件移动到其父目录时出错EPERM?

时间:2015-08-05 06:07:26

标签: node.js fs

我发现这个answer说要使用mv模块。

但是,如果我想将文件移动到其父目录,它似乎不起作用。

例如,我想将/tmp上的所有文件移至/

var root = process.cwd(); // the directory where i run the script

mv(root + "/tmp", root, { mkdirp: true }, function(err) {
  if(err) { return logger.error(err); }
});

我收到了这个错误:

error:  Error: EPERM, rename 'C:\Users\myusername\Documents\test\tmp'

我认为这是因为在NodeJS中移动会使用rename解决方法,并且无法将其重命名为父目录。

任何解决方案?感谢

1 个答案:

答案 0 :(得分:-1)

没关系,使用fs-extra模块here

fs.move实际上有效