We help IT Professionals succeed at work.

Is file currently open?

mark_s
mark_s asked
on
199 Views
Last Modified: 2010-05-03
Is there a way of determining if a file is currently open? I need to know when a large data file copied to my machine across an ISDN line is complete. My application is VB3 and running under NT and I think FileLen() may return a file size before the file is complete.
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
mark_s,
Try to open the file. If you get an error of 55, the file is already open. The code was used in VB3.
Regards
Dalin.

   On error goto errorTrap
   lifh = FreeFile ' get the next available free file handle
   Open TheFile For Input As lifh ' try and open it for reading
   Close lifh ' be sure to close it
   Exit Function ' or sub

ErrorTrap:
   Select Case Err
         
   Case 52  'bad file name or number
         
          Case 53  'file not found
           
          Case 55  'file already open
         
       
          Case 75  'path/file access error
         
          Case 76  'path not found
       
          Case Else ' something else happened - so just report it
       
   End Select

End Function/sub

Commented:
Error 55 means your own program has the file open, it won't be returned if some other process has it open.

The error you are most likely to get back if another process has the file locked is 70 Permission denied, however I have seen others on certain networks (such as 76 Path/File access error, which you wouldn't expect in a case like this).

Commented:
Thank you, alamo, for the clarification.
I was just thinking of file opened by the app itself. My mistake.
Sorry for mis-understand your question, mark_s.
Regards
Dalin


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.