AvianFlu/ncp — Issue #8: Can't copy files to a directory
Author: dwhitlow
Created: 2012-01-06 23:56:16+00:00
State: open

The command line cp utility can copy files to a directory, but ncp cannot. Example:
cp path/to/file.txt path/to/dir

Replacing onFile with the following code will resolve the issue. I'm just too lazy to fork the project, add test cases, yadda yadda yadda:

function onFile(file) {
var target = file.replace(currentPath, targetPath);
path.exists(target, function (exists) {
if (exists) {
if (fs.statSync(target).isDirectory()) {
target = path.join(target, path.basename(file));
} else {
return rmFile(target, function () {
copyFile(file, target);
});
}
}
copyFile(file, target);
});
}