Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How waiting the end of the copy of a file before mode it ?

Status
Not open for further replies.

ThomasMatelart

Programmer
Apr 17, 2001
14
0
0
BE
I'm spying a folder after new files.
When a new file is coming, i would like to copy it in a new folder.

BUT, if the file is big, the file exists in the folder before the end of the copy.

How can i wait the complete transfert of the file before copy it in the new folder ?

 
How are the files being copied? Programatically or manually? Are you using the File system object to copy the files once they are in the folder?
 
Yes, i use File System Object to copy the files once they are in the folder.
But the files are copied in the folder by external process.
 
I have this same question. (More or less...)

Files are uploaded into a directory from a web page and I want another program to copy the files out of that directory onto a network drive. The copying process will run about once every minute (I'm tying it into another program). I want to make sure the files in the folders are complete (fully uploaded) before I move them to the network drive.

Here's what I have to get the files from the web server. I was thinking I could check the file size to determine if it was complete. Better ideas are appreciated. Thanks.

Code:
Dim lfsoUpload As New FileSystemObject
Dim lfldUpload As Folder
Dim lfldSubfolder As Folder
Dim lfil As File

Set lfldUpload = lfsoUpload.GetFolder("\\server_name\uploads\")

'Get the subfolders of uploads folder
For Each lfldSubfolder In lfldUpload.SubFolders
   
    Set lfldSubfolder = lfsoUpload.GetFolder("\\server_name\uploads\" & lfldSubfolder.Name & "\")
    
    'Get the files in the subfolders
    For Each lfil In lfldSubfolder.Files
        'check to see if file is complete...?

    Next
      
Next
 
I found this routine once and it worked for me.
To invoke it use
Code:
   If FileLocked(file path and name) Then....

 Function FileLocked(strFileName As String) As Boolean
    Dim fh
          On Error Resume Next

      ' If the file is already opened by another process,
      ' and the specified type of access is not allowed,
      ' the Open operation fails and an error occurs.
      fh = FreeFile
      Open strFileName For Binary Access Read Write Lock Read Write As #fh
      Close #fh

      ' If an error occurs, the document is currently open.
      If Err.Number <> 0 Then
         ' Display the error number and description.
         'MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
         FileLocked = True
         Err.Clear
      End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top