filelock

How to check in command-line if a given file or directory is locked (used by any process)?

风格不统一 提交于 2019-11-26 12:22:29
I need to know that before any attempt to do anything with such file. dbenham Not sure about locked directories (does Windows have that?) But detecting if a file is being written to by another process is not difficult. @echo off 2>nul ( >>test.txt echo off ) && (echo file is not locked) || (echo file is locked) I use the following test script from another window to place a lock on the file. ( >&2 pause ) >> test.txt When I run the 2nd script from one window and then run the 1st script from a second window, I get my "locked" message. Once I press <Enter> in the 1st window, I get the "unlocked"

PowerShell script to check an application that&#39;s locking a file?

会有一股神秘感。 提交于 2019-11-26 08:03:29
问题 Using in PowerShell, how can I check if an application is locking a file? I like to check which process/application is using the file, so that I can close it. 回答1: You can do this with the SysInternals tool handle.exe. Try something like this: PS> $handleOut = handle PS> foreach ($line in $handleOut) { if ($line -match '\S+\spid:') { $exe = $line } elseif ($line -match 'C:\\Windows\\Fonts\\segoeui\.ttf') { "$exe - $line" } } MSASCui.exe pid: 5608 ACME\hillr - 568: File (---) C:\Windows\Fonts

How to check for file lock? [duplicate]

烈酒焚心 提交于 2019-11-25 23:07:28
问题 This question already has answers here : Is there a way to check if a file is in use? (18 answers) Closed 3 years ago . Is there any way to check whether a file is locked without using a try/catch block? Right now, the only way I know of is to just open the file and catch any System.IO.IOException . 回答1: No, unfortunately, and if you think about it, that information would be worthless anyway since the file could become locked the very next second (read: short timespan). Why specifically do