# encoding: ascii
# api: powershell
# title: Test-FileLock
# description: simle function to determine is file locked by external program or not.
# version: 0.1
# author: Vadims Podans
# license: CC0
# x-poshcode-id: 1363
# x-archived: 2017-04-30T12:53:08
# x-published: 2010-10-02T04:52:00
#
#
filter Test-FileLock {
    if ($args[0]) {$filepath = gi $(Resolve-Path $args[0]) -Force} else {$filepath = gi $_.fullname -Force}
    if ($filepath.psiscontainer) {return}
    $locked = $false
    trap {
        Set-Variable -name locked -value $true -scope 1
        continue
    }
    $inputStream = New-Object system.IO.StreamReader $filepath
    if ($inputStream) {$inputStream.Close()}
    @{$filepath = $locked}
}
