Skip to content

Instantly share code, notes, and snippets.

@ifree
Created September 5, 2011 12:10
Show Gist options
  • Save ifree/1194808 to your computer and use it in GitHub Desktop.
Save ifree/1194808 to your computer and use it in GitHub Desktop.
#powershell check if file is locked
function IsFileLocked($filename) {
$result = $false
$fileinfo = [System.IO.FileInfo] (gi $filename).fullname
try {
$stream = $fileInfo.Open([System.IO.FileMode]"Open",[System.IO.FileAccess]"ReadWrite",[System.IO.FileShare]"None")
$stream.Dispose()
} catch [System.IO.IOException] {
$result = $true
}
$result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment