I never knew that Windows did this but apparently this is a feature of the DeleteFile SDK function. Not a lot that node can do about this.
Node.js fs.unlink deletes locked file when it becomes unlocked on Windows
题
If I use fs.unlink to delete a locked file on Windows then the callback is called with an error, as expected. When I subsequently terminate node the file is deleted. I am at a loss as to how this might be happening and would prefer that locked files are not deleted. I should add that it is node that holds the lock so the file is presumably deleted when the lock is released.
解决方案
其他提示
fs.unlinkSync('filename.extension');
will delete the file only if its unlocked. in case if the file is used it will give error
Resource is busy
不隶属于 StackOverflow