Reputation: 33
After running the following code, the file handle is still opened on Windows, how to close it?
var Name="1.mp4";
var inp = fs.createReadStream("Temp/" + Name);
var out = fs.createWriteStream("Video/" + Name);
inp.pipe(out);
inp.on("end", function() {
fs.unlink("Temp/" + Name, function (){
out.close();
console.log("unlink this file:",Name );
});
});
screen shot: file handle not colsed on Windows
Upvotes: 1
Views: 478
Reputation: 74645
You need to close inp
too not just out
. You can do this by calling inp.close();
at the same point you already call out.close();
.
Also you could simply move the file with
fs.rename("Temp/" + Name, "Video/" + Name, function() {
console.log("Renamed:", Name)
});
rather than rewriting the file.
Upvotes: 1