Set timer until files are done copying

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crayhouse
    New Member
    • Oct 2012
    • 3

    Set timer until files are done copying

    Just to start this off right, thanks for any help.

    I have a database that has network locations to documents stored as \\networkresour ceblah\document s\file.pdf in a text field.

    After the user is done and presses a button. Here are the actions that it goes through after that.
    1. Copies files from the network location to a temp folder on their computer.
    2. Uses pdftk to join all of the documents together and name the new document (in the temp folder)
    3. Looks for the new document to exist in the temp folder
    4. Copies the file to a new location
    5. Verifies that the named document is in the new location
    6. Deletes all of the files in the temporary location.


    The problem I am running in to is...if the file is large then the file name exists before the document is finished building itself. When the database sees the document name, even if it is only 0 kb, then it copies it at that point and deletes the original. I have placed this code to wait, but it doesn't always work, since the code is finite, and has a point that it quits waiting.

    Code:
    StartTimer:
        If fso.FileExists(SPath & FileName) Then
            Wait = Timer
            While Timer < Wait + 5
                DoEvents
            Wend
            fso.CopyFile (SPath & FileName), NPath, True
            fso.CopyFile (SPath & FileName), DPath, True
        Else
            GoTo StartTimer
        End If
        
        Wait = Timer
        While Timer < Wait + 1
        DoEvents
        Wend
    
    StartSecondTimer:
        If fso.FileExists(DPath & FileName) Then
            Kill SPath & "*.*"
        Else
            Wait = Timer
            While Timer < Wait + 1
            DoEvents
            Wend
            GoTo StartSecondTimer
        End If
    As you can see, I look for the file in the temp directory, wait 5 seconds, copy it across, wait 1 second, look for the new file in the new location, then delete the originals. This feels like an eternity sometimes. Is there a way to determine if a file is in use or "being built", prior to copying it. That would allow me to drastically reduce time to the user.
  • IraComm
    New Member
    • Oct 2012
    • 14

    #2
    You could check the size of the file every second or so.
    If it does not increase after 3~5 seconds the file is done being made.
    If the "pdftk" program is a seperate program invoked to combine the files, you could use a function that is able to see all the programs running. When it disapears, your done.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      If you issue a DOS Rename (back to the original name of course) command to any file that is in progress then it will fail.

      If your timer routine checks the file this way every time it is triggered then it should eventually detect the end of the process and be in a position to invoke the rest of the code.

      Comment

      Working...