Results 1 to 3 of 3

Thread: Most efficient way to check if file is in use

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Cool 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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Most efficient way to check if file is in use

    try to delete it

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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
  •  



Click Here to Expand Forum to Full Width