Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created June 2, 2018 13:01
Show Gist options
  • Save csharpforevermore/2799e74e7b4d33d8177a6300d99c465a to your computer and use it in GitHub Desktop.
Save csharpforevermore/2799e74e7b4d33d8177a6300d99c465a to your computer and use it in GitHub Desktop.
Is this folder in use and which application is locking the folder for me?
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
}
@csharpforevermore
Copy link
Author

Thanks to the user frank from website SuperUser for his solution here

@csharpforevermore
Copy link
Author

csharpforevermore commented Jun 2, 2018

Feature must be enabled with this snippet first in Powershell openfiles /local on (some versions of Windows may have issues with this command when running on a 64-bit machine, occasionally reporting the error message ERROR: The target system must be running a 32 bit OS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment