I am trying to move files from one directory to another using the mv module. The problem is, once the files are moved, the source directory gets deleted. I dont want this, I want only the files that are moved to be deleted from the source directory. The source directory should remain (even if it is empty). Not sure how to do this with the mv module (or if there are any other options).
My code
var pathToPdf = path.join(__dirname, '../pathToPdf/');
` var intermediate = path.join(__dirname, '../intermediate/');
fs.readdir(pathToPdf, function(err, files) {
if (err) return;
files.forEach(function(file){
mv(pathToPdf, intermediate, function(err) {
if(err){
console.log("oops!")
}
});
----move code ---
This code is moving the files to intermediate directory, but the pathToPdf directory gets deleted, which I want to avoid. Please advise.
mv().mv()is written to work. Also, why are you doing afiles.forEach()and then not using thefileyou are iterating? Your code looks wrong in that regard.