我正在尝试通过 Node ncp library 过滤文件但它的过滤器不起作用。 一旦过滤器返回错误,它就会中断整个复制过程
ncp(source, destination, options, function (err) {
if (err) {
console.error("backup error:", err);
}
console.log("Backup of done!');
});
var options = {
filter: function (file) {
console.log("copying file:", file);
var res = file.toString().indexOf("\\testdrive") !== -1;
console.log("res:", res);
return !res;
},
//filter: new RegExp("\\testdrive"),//Or RegEx intance
};
因此,一旦过滤函数或 RegEx 实例得到错误结果,整个复制就会中断
options.filter - a RegExp instance, against which each file name is tested to determine whether to copy it or not, or a function taking single parameter: copied file name, returning true or false, determining whether to copy file or not.
最佳答案
刚刚找到解决方案: 似乎过滤器 RegExp/function 不仅会被 ncp 应该复制的文件名调用,还会被文件夹名调用。 它过滤的第一个文件夹名称显然是您作为源传递给 ncp 的文件夹名称。如果失败,ncp 将停止复制该文件夹中的任何内容。
关于node.js - Node ncp 过滤器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45842768/