Delay Copy in Batch File

Is there a way to create a bat file to copy over several files in intervals?
Meaning copy one file then wait 60 seconds and copy over the next file?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

SCCMCanuckConnect With a Mentor Network AnalystCommented:
High tgarrity, there are a number of options available, please see below:

Let me know how you make out

Lee W, MVPConnect With a Mentor Technology and Business Process AdvisorCommented:
Using the ping command in Binarymime's link:

FOR /f "tokens=*" %%a in ('dir /b') do (
   copy "%%a" "x:\path\to\copy\to"
   ping -w 60000

The for command cycles through the list of files in the directory, effectively doing one at a time - the ping command causes a 60 second delay (60,000 milliseconds = 60 seconds).
Bill PrewCommented:
I can't help but ask, since it could affect what solutions are recommended.  What problem or effect are you trying to accomplish by pausing in between file copies?  Is it true that you don't want to copy the same file over at different times, but different files that already exist in a folder?

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

tgarrityAuthor Commented:
The scenario:

I have a folder on Server A containing 500 .xml files and 15,000 .pdf files.
The .xml files contain info on where to file .pdf files on Server B.
I need to copy one .xml file at a time  to Server B every 120 seconds.
The .pdf files can be ignored, but wanted to make everyone aware as a copy *.* will not work in this case. I'm having to copy the .xml files one at a time due to a resource issue on Server B.
If I dump all 500 .xml files onto Server B, Server B will not process the .xml files and in turn will not correctly file the .pdf files.
Bill PrewConnect With a Mentor Commented:
Okay, so something like lee proposed should work, although you want to use an invalid IP address, not a valid one.  so something like:

FOR /f "tokens=*" %%a in ('dir /b *.xml') do (
   copy "%%a" "x:\path\to\copy\to"
   ping -w 60000

Okay, to solve this issue, forget about delays etc... that's nonsense

Your code should consist of a single batch file which reads the information from each xml file one-at-a-time and then process pdf files accordingly.

From a top-level design viewpoint, the code (in pseudocode) shoulf look something like this:

FOR all XML files in the XML folder/s
   get the next XML file
   process it's data
   file PDF files accroding to data

It's as simple as that.

I'm busy right now writing code elsewhere however, when I am through with that I will return here to assist you further if in the meantime another expert has not already done so.
tgarrityAuthor Commented:
I ended up using the following script:

FOR /f "tokens=*" %%a in ('dir /b *.xml') do (
   copy "%%a" "Z:\"
   ping -n 90


Thanks for all the help!
All Courses

From novice to tech pro — start learning today.