How Can I Tell When a File is no Longer Locked?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
wjfinniganjds
Junior Coder
Posts: 24
Joined: Tue Sep 15, 2009 3:20 pm

How Can I Tell When a File is no Longer Locked?

Post by wjfinniganjds » Thu Feb 24, 2011 6:20 pm

I'd like to kick off a rename of a file as soon as it is written, but I am not sure how to tell when the program has released the lock.

Thanks!
I think I can automate that!

wjfinniganjds
Junior Coder
Posts: 24
Joined: Tue Sep 15, 2009 3:20 pm

THis might work if you want to insert a VBA bit.

Post by wjfinniganjds » Thu Feb 24, 2011 7:09 pm

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

MySubje()

Private Sub MySubje()
On Error Resume Next
Dim strFileName
' Full path and name of file.
strFileName = "k:\test.txt"
Set fLog = fso.OpenTextFile(strFileName, ForAppending, True)
If Err.Number = 70 Then
WScript.Echo "locked"
Else
WScript.Echo "not locked"
End If
Err.Clear
End Sub
I think I can automate that!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts