How can I find out which process is locking a file or folder in Windows?
For instance, when trying to delete a folder, Windows reports this:
The action can't be completed because the folder is open in another program
Happens the same with a file, but how do I find out what program or application is currently using it and preventing me from deleting the file or folder?
Answer
PowerShell method:
IF((Test-Path -Path $FileOrFolderPath) -eq $false) {
Write-Warning "File or directory does not exist."
}
Else {
$LockingProcess = CMD /C "openfiles /query /fo table | find /I ""$FileOrFolderPath"""
Write-Host $LockingProcess
}
The openfiles
command needs to have support for local files enabled, by running openfiles /local on
and restarting.
More details How to find out which process is locking a file or folder in Windows
No comments:
Post a Comment