Created
December 23, 2015 15:09
-
-
Save crshnbrn66/7a3f58ac8ac485a84865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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