I'm trying to make a function that checks if file is opened or in use by another app or process using fs
and here is my attempt to do this
function isFileInUse() {
try {
const file = path.join(__dirname, '20200201072955946-2.jpg');
//try to open file for checking if it is in use
fs.access(file, fs.constants.W_OK, (err) => {
if (err) {
console.log('File is in use');
} else {
console.log('File is not in use');
}
});
return false;
}
catch(error) {
console.log(error);
return true;
}
}
isFileInUse()
this code somehow move the the image with no error even if it's run by another app like notepad++ or by image viewer
if someone can tell me what i'm doing wrong on this matter or help with this . that be great
thanks in advance