none
vbs - wait for file to be completely moved before continuing RRS feed

  • Question

  • Hi, I have a script which moves a file to a zip file for archiving. Is there a way of telling the vbs script to pause untill the file has been fully copied.

    My script so far is:

     

    Set DestFldr=appShell.NameSpace(ziploc)			
    									
    Set SrcFldr=appShell.NameSpace(sWD & chr(92) & floc)
    			
    DestFldr.MoveHere (sWD & chr(92) & filename)

     

    The problem I have is that depending on the size of the file being copied, the DestFldr.MoveHere command doesn't necessarily complete before moving on, and further down the script I delete the original file (because MoveHere actually seems to copy to the zip file, and not Move), but obviously because the file is still copying, I can't delete it.

    Monday, October 11, 2010 3:09 PM

Answers

  • Count=DestFldr.Items().Count

    DestFldr.MoveHere (sWD & chr(92) & filename)

    Do While Count=DestFldr.Items().Count

      WScript.Sleep 100

    Loop

    • Marked as answer by iGGt Wednesday, October 13, 2010 3:00 PM
    Tuesday, October 12, 2010 6:27 AM

All replies

  • you should try using the FileSystemObject MoveFile method instead.

     

    http://msdn.microsoft.com/en-us/library/2wcf3ba6%28v=VS.85%29.aspx

    Monday, October 11, 2010 3:28 PM
  • Count=DestFldr.Items().Count

    DestFldr.MoveHere (sWD & chr(92) & filename)

    Do While Count=DestFldr.Items().Count

      WScript.Sleep 100

    Loop

    • Marked as answer by iGGt Wednesday, October 13, 2010 3:00 PM
    Tuesday, October 12, 2010 6:27 AM
  • Count=DestFldr.Items().Count

    DestFldr.MoveHere (sWD & chr(92) & filename)

    Do While Count=DestFldr.Items().Count

      WScript.Sleep 100

    Loop

    Cheers for that, it works perfectly.
    Wednesday, October 13, 2010 3:00 PM