I am trying to delete one file and one folder asynchronously by using fs-extra. But it is throwing the following error.
import fse from 'fs-extra';
function deleteMethod (foldername){
fse.remove(`${foldername}-tar.gz`)
.then(() => fse.remove(foldername))
.then(() => çonsole.log('successfully deleted'))
.catch((err) => console.log(err))
}
Response:
{ [Error: EBUSY: resource busy or locked, unlink'D:rootpath\15\image.jpg']
errno: -4082,
code: 'EBUSY',
syscall:'unlink',
path: 'D:rootpath\15\image.jpg' }
Error occurs in second delete statement. Can someone please explain why it is happening.
This issue arises because another program is currently accessing that file and may change its contents at any time (theoretically), and thus your OS will not allow you to make changes as well. This is true of all operating systems. The OS will not want multiple copies of the same file open in different programs, as this will make it impossible to determine which copy is the true version, or how to merge the changes properly, and so on. Essentially, you must terminate the program currently utilizing that file in order to read/write to it.