none
VB Script to Copy files one at a time and wait for Server to take file. RRS feed

  • Question

  • I feel I am close, but not sure what I am doing wrong. I code in VB .Net, and am new to VB Scripting.

    Here is my code so far.

    Set fso = CreateObject("Scripting.FileSystemObject")
    OrgFiles = "W:\1154229\VDD\Data\Splits\"
    Watch = "Z:\Glenn2\Working\Test\"
    
      For Each file in GetFiles(OrgFiles, "*.*")
          fname2 = GetFileName(file)
    
                 fso.copyfile file, Watch & "\", fname2
    
                 Do While IO.File.Exists(Watch & "\" & fname2)
                    Threading.Thread.Sleep(20)
                 Loop
      Next
    
            MsgBox("Files Processed")

    Wednesday, July 1, 2015 5:45 PM

Answers

  • This is about as close as you are going to get.

    Const Watch = "Z:\Glenn2\Working\Test\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder("W:\1154229\VDD\Data\Splits")
    
    For Each file in folder.Files
        file.Copy Watch
        Do While fso.FileExists(Watch & file.Name)
            WScript.Sleep 300
        Loop
    Next
    
    


    \_(ツ)_/




    • Edited by jrv Wednesday, July 1, 2015 10:02 PM
    • Marked as answer by Broggy69 Wednesday, July 1, 2015 10:33 PM
    Wednesday, July 1, 2015 9:53 PM

All replies

  • I am trying to create a script to copy files wait until it is processed by a server, then copy the next.

    Below is what I have but get an error Line 5; Char 3: Error Type mismatched: GetFIles; Code 800a000d

    What am I doing wrong?

    Set fso = CreateObject("Scripting.FileSystemObject")
    OrgFiles = "W:\1154229\VDD\Data\Splits\"
    Watch = "Z:\Glenn2\Working\Test\"
    
      For Each file in GetFiles(OrgFiles, "*.*")
          fname2 = GetFileName(file)
    
                 fso.copyfile file, Watch & "\", fname2
    
                 Do While IO.File.Exists(Watch & "\" & fname2)
                    Threading.Thread.Sleep(20)
                 Loop
      Next
    
            MsgBox("Files Processed")

    • Merged by Youjun Tang Thursday, July 2, 2015 5:37 AM duplicate
    Wednesday, July 1, 2015 5:04 PM
  • This forum supports Visual Basic for the .Net Framework (VB 7 and later). For help with VBScript code, try the Official Scripting Guys Forum.

    Wednesday, July 1, 2015 5:14 PM
  • This is not necessary.  The file copy does return until the file is completely copied.

    You are mixing VB.Net with VBScript which cannot work

    VBScript cannot use wildcards.


    \_(ツ)_/

    Wednesday, July 1, 2015 6:42 PM
  • Ohh I didn't know that VB can't use wild cards. Anyway around that at all? Or can VB Script call a bat file? But I do need the wait, that is a customer requirement.

    After the file is copied I have to wait until the previous file taken by the server processes, otherwise the server slows way down.

    Wednesday, July 1, 2015 7:56 PM
  • It is not a customer requirement.  Why would anyone say to do something totally impossible to do in VBScript.  If there is no error then  the file has been copied.  That is how computer systems work.

    You are not writing any real script it is just a bunch of guesses.  I recommend that you take time to learn how to write a script before you charge someone for guesswork.

    Here is a link to get you started: https://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx?f=255&MSPPError=-2147217396


    \_(ツ)_/

    Wednesday, July 1, 2015 8:05 PM
  • You can use wild cards in PowerShell:

    Get-ChildItem W:\1154229\VDD\Data\Splits\* -File | Copy-Item -Target Z:\Glenn2\Working\Test

    You just need to check the error stack after it finishes to see if any files failed.


    \_(ツ)_/


    • Edited by jrv Wednesday, July 1, 2015 8:08 PM
    Wednesday, July 1, 2015 8:08 PM
  • It is not a customer requirement.  Why would anyone say to do something totally impossible to do in VBScript.  If there is no error then  the file has been copied.  That is how computer systems work.

    You are not writing any real script it is just a bunch of guesses.  I recommend that you take time to learn how to write a script before you charge someone for guesswork.

    Here is a link to get you started: https://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx?f=255&MSPPError=-2147217396


    \_(ツ)_/

    Yes it is a customer requirement. Only one file can be copied at a time, and I have to wait until the server takes that file for further processing. It is not just copy and it is done.

    There are other work flows happening to the hot folder where files are being copied.

    That is why I have to wait until the file has been taken by the server after copying the file. I do have a VB program that does this, but they wanted to know if I could provide a VB Script instead. So I am not making guess work, but doing what the customer has asked.

    Moving forward I'll look at PowerShell as well, as it sounds like VB Script will not work for the customers requirements.

    Wednesday, July 1, 2015 8:58 PM
  • Only one file is copied at a time.  You cannot copy more than one file at a time in ma single thread.  The VBScript code you posted cannot be made to work.

    I think you need to spend a bit of time learning how a computer system works.  The copy copies thefile one part at a time by creating a new file on the remote then write to it then closing it.  When the copy returns the file is guaranteed to be onm the server,  There is nothing to wait for and no way to wait.  Computer file systems 101.  It is like that in all operating systems and always has been.  There is no point to what the customer is saying and no way to do what you are asking.


    \_(ツ)_/

    Wednesday, July 1, 2015 9:08 PM
  • Only one file is copied at a time.  You cannot copy more than one file at a time in ma single thread.  The VBScript code you posted cannot be made to work.

    I think you need to spend a bit of time learning how a computer system works.  The copy copies thefile one part at a time by creating a new file on the remote then write to it then closing it.  When the copy returns the file is guaranteed to be onm the server,  There is nothing to wait for and no way to wait.  Computer file systems 101.  It is like that in all operating systems and always has been.  There is no point to what the customer is saying and no way to do what you are asking.


    \_(ツ)_/

    I understand one file is copied at a time. However only one file can be in the hot folder at a time. So if a file exist in the hot folder, I have to wait until the server takes that file. It can take 5-15 minutes between file processes.

    I understand how computers to work. I also understand how the specialized software the site uses for their work flow works, and really did not feel the need to go into details how it works. Either VB Script can do what I need or it can't.

    I learned today from you it can't. Understood. I know a bat file can do something similar setting timers, but I never know how long it takes server to process a file, I am looking into PowerShell but most likely will recommend to customer to use the VB program I created.

    Wednesday, July 1, 2015 9:43 PM
  • You are now adding extra requirements.  There is no mention of a hot folder - whatever that is. The code you posted will not test hotness or anything else.

    Perhaps you would do better to hire a consultant to sit down with you and scope out what it is you need to do. 

    The only way you can test a file in VBScrtip is with the "FileExists"  method and the ojnly way to wait is to use WScript.Sleep.

    Go through the tutorial I posted to see how to use the file system and how to write a vbscript.  The artcles are short and very useful.  After you understand how a script works you will probably be better equipeed to ask a question.


    \_(ツ)_/

    Wednesday, July 1, 2015 9:49 PM
  • This is about as close as you are going to get.

    Const Watch = "Z:\Glenn2\Working\Test\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder("W:\1154229\VDD\Data\Splits")
    
    For Each file in folder.Files
        file.Copy Watch
        Do While fso.FileExists(Watch & file.Name)
            WScript.Sleep 300
        Loop
    Next
    
    


    \_(ツ)_/




    • Edited by jrv Wednesday, July 1, 2015 10:02 PM
    • Marked as answer by Broggy69 Wednesday, July 1, 2015 10:33 PM
    Wednesday, July 1, 2015 9:53 PM
  • You are now adding extra requirements.  There is no mention of a hot folder - whatever that is. The code you posted will not test hotness or anything else.

    Perhaps you would do better to hire a consultant to sit down with you and scope out what it is you need to do. 

    The only way you can test a file in VBScrtip is with the "FileExists"  method and the ojnly way to wait is to use WScript.Sleep.

    Go through the tutorial I posted to see how to use the file system and how to write a vbscript.  The artcles are short and very useful.  After you understand how a script works you will probably be better equipeed to ask a question.


    \_(ツ)_/

    No I didn't add extra requirements. I ask for help in copying files, and waiting until the server processed. My question: "VB Script to Copy files one at a time and wait for Server to take file" Yea I didn't mention a hot folder. A hot folder is used by the work flow program that checks to see if a file exist in the hot folder. if one exist it processes the file through the work flow that was created. If 5 files are copied it tries to process all five files.

    So my scope of copying files and waiting for server processed the file was a simplistic description.

    Wednesday, July 1, 2015 10:29 PM
  • This is about as close as you are going to get.

    Const Watch = "Z:\Glenn2\Working\Test\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder("W:\1154229\VDD\Data\Splits")
    
    For Each file in folder.Files
        file.Copy Watch
        Do While fso.FileExists(Watch & file.Name)
            WScript.Sleep 300
        Loop
    Next
    
    


    \_(ツ)_/





    Thank you. That is what I was looking for. :)
    • Marked as answer by Broggy69 Wednesday, July 1, 2015 10:33 PM
    • Unmarked as answer by Broggy69 Wednesday, July 1, 2015 10:33 PM
    Wednesday, July 1, 2015 10:30 PM