|
-
Dec 22nd, 2004, 12:56 PM
#1
Thread Starter
Hyperactive Member
Most efficient way to check if file is in use
What would be the most efficient way to check if a file, or list of files are in use by another process?
Thanks
He who has conquered himself, is far greater than he who has conquered a thousand men... - The Buddha
-
Dec 22nd, 2004, 12:57 PM
#2
Re: Most efficient way to check if file is in use
try to delete it
-
Dec 22nd, 2004, 01:13 PM
#3
Re: Most efficient way to check if file is in use
I think this should fail if the file is already opened by another program:
Code:
Option Explicit
Private Sub Form_Load()
Dim Filename As String
On Error GoTo ErrorHandler
Filename = "g:\videot\trailer.avi"
Open Filename For Binary Lock Read Write As #1
Close #1
Exit Sub
ErrorHandler:
Select Case Err.Number
Case 70 'access denied
MsgBox "File is already opened and reserved by another application.", vbInformation, "Error"
Case Else
MsgBox Err.Number & ": " & Err.Description, vbInformation, Filename
End Select
Close #1
End Sub

Edit Tested and works! I opened VirtualDub with the file mentioned, I got error 70 error denied. If I didn't have the file open in VirtualDub, I got no error.
Last edited by Merri; Dec 22nd, 2004 at 01:33 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|