Skip to content

Instantly share code, notes, and snippets.

@crshnbrn66
Created December 23, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crshnbrn66/7a3f58ac8ac485a84865 to your computer and use it in GitHub Desktop.
Save crshnbrn66/7a3f58ac8ac485a84865 to your computer and use it in GitHub Desktop.
function Test-FileOpen
{
<#
.SYNOPSIS
Tests to see if a file is locked
.DESCRIPTION
Returns true if the file can be opened. False if the file is open already.
.PARAMETER path to file
The path to a file.
.EXAMPLE
test-Fileopen -FileToOpen "d:\temp\test.log"
#>
Param
( [string]$FileToOpen)
try
{
$openFile =([system.io.file]::Open($FileToOpen,[system.io.filemode]::Open))
$open =$true
$openFile.close()
}
catch
{
$open = $false
}
$open
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment