PoshCode Archive  Artifact Content

Artifact 2ca42effe1961a8a8ec264825d58388d3ca31860bb4f679cc8b264fc9e1c2110:

  • File Test-FileLock.ps1 — part of check-in [555519ee9d] at 2018-06-10 12:56:56 on branch trunk — simle function to determine is file locked by external program or not. (user: Vadims Podans size: 739)

# 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}
}