[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Is file currently open?

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.
0
mark_s
Asked:
mark_s
  • 2
  • 2
1 Solution
 
alamoCommented:
To see if the file is done being written open it "Lock Read" with error trapping on. If the open fails you can detect it, wait a little bit, and try again. You also need to error-trap your first read of the file, since in some network environments opens succeed but don't actually acquire the lock until the file is accessed.

"Lock Read" should be enough but if that doesn't always work, try "Lock Read Write" - file locking can be a tricky thing sometimes.

Hope this helps!
0
 
DalinCommented:
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

0
 
alamoCommented:
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).
0
 
DalinCommented:
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


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now