The question:
问题是:
How to copy one folder to another in NodeJS, overwriting only files that differ?
如何在NodeJS中将一个文件夹复制到另一个文件夹,只覆盖不同的文件?
About fs-extra "copy" method:
关于fs-extra“复制”方法:
It seems that the copy method from fs-extra does not have the option to skip identical files (that have not undergone any modification).
似乎fs-extra的复制方法没有跳过相同文件(没有经过任何修改)的选项。
There is the overwrite
option, but it only gives you the choice to overwrite in all cases, even when the files are identical, or to not overwrite, even if the files differ.
有覆盖选项,但它只允许您在所有情况下覆盖,即使文件相同或不覆盖,即使文件不同。
1 个解决方案
#1
0
I found mattijs/node-rsync and jedrichards/rsyncwrapper, both performing well and running in Linux/Windows/etc.
我找到了mattijs / node-rsync和jedrichards / rsyncwrapper,它们都运行良好并在Linux / Windows /等中运行。
For ease and freedom of choice, I decided to stick with the second option.
为了方便和*选择,我决定坚持第二种选择。
Examples (there are more options described in the readme's)
示例(自述文件中描述了更多选项)
Single file:
单个文件:
rsync({
src: "file.txt",
dest: "tmp/file.txt"
},function (error,stdout,stderr,cmd) {
if ( error ) {
// failed
console.log(error.message);
} else {
// success
}
});
Full directory:
完整目录:
rsync({
src: "src-folder/",
dest: "dest-folder",
recursive: true,
exclude: ["*.txt"]
},function (error,stdout,stderr,cmd) {
if ( error ) {
// failed
console.log(error.message);
} else {
// success
}
});
#1
0
I found mattijs/node-rsync and jedrichards/rsyncwrapper, both performing well and running in Linux/Windows/etc.
我找到了mattijs / node-rsync和jedrichards / rsyncwrapper,它们都运行良好并在Linux / Windows /等中运行。
For ease and freedom of choice, I decided to stick with the second option.
为了方便和*选择,我决定坚持第二种选择。
Examples (there are more options described in the readme's)
示例(自述文件中描述了更多选项)
Single file:
单个文件:
rsync({
src: "file.txt",
dest: "tmp/file.txt"
},function (error,stdout,stderr,cmd) {
if ( error ) {
// failed
console.log(error.message);
} else {
// success
}
});
Full directory:
完整目录:
rsync({
src: "src-folder/",
dest: "dest-folder",
recursive: true,
exclude: ["*.txt"]
},function (error,stdout,stderr,cmd) {
if ( error ) {
// failed
console.log(error.message);
} else {
// success
}
});