Copy multiple files with a delay between each

Dell / OPTIPLEX 755
September 10, 2009 at 05:54:01
Specs: Windows XP, Intel Core 2/1.99 GB
I have an archive directory full of text files (.txt) that all start with the prefix harbil followed by a numeric sequence indicating the hour, minute and second they were created. These files contain data used by a software application and are collected daily in case the software crashes. Typically, the information is sent over one text file at a time to the software directory at which time the information is taken from the text file by the application and placed in a queue. I have created a batch file that will take all the files from the archive directory, remove the numeric sequence and place them in the software directory in such a manner that they will all be named simply harbil.txt and overwrite one another as they are created. The problem is that when I run the batch file only the last set of information is added to the application queue. I believe I need to copy each file from the archive directory to the software directory one at a time with a pause in between in order to allow the software to grab the information before the file is overwritten. I have tried many times and failed. I cannot figure out how to loop the execution of the file copy to go one at a time and/or slow the process down. HELP!

See More: Copy multiple files with a delay between each

Report •

September 10, 2009 at 06:13:58
Add this to your batch to make it wait before doing the next file. The time is in milli-seconds, so 60000 is 60 seconds
Also if this doesn't fit into you current batch, you may try posting what you currently have so that we can take a look at what you are working with.

PING -n 1 -w 60000 >NUL

Report •

September 10, 2009 at 06:23:18
Here is what I have so far. This is a bit of a mix of ideas I've gotten from other people so I must admit I don't know what everything in here is doing. It works in as much as it does make copies of the files in the correct directory but it works to fast for the software application to keep up:

@echo off & setLocal EnableDELAYedExpansion

pushd "G:\GROUPS\color logics\FMData\FMDATA BU"
for /f "tokens=* delims= " %%a in ('dir /b/a-d "G:\GROUPS\color logics\FMData\FMDATA BU\harbil*.dci"') do (copy "G:\GROUPS\color logics\FMData\FMDATA BU\%%a" "G:\GROUPS\color logics\FMData\Harbil.dci")

Report •

September 10, 2009 at 07:49:29
So to add this, just gotta do something like this:

@echo off & setLocal EnableDELAYedExpansion

pushd "G:\GROUPS\color logics\FMData\FMDATA BU"
for /f "tokens=*" %%a in ('dir /b/a-d "harbil*.dci"') do (
copy "%%a" "G:\GROUPS\color logics\FMData\Harbil.dci"
PING -n 1 -w 60000 >NUL

Report •

Related Solutions

September 10, 2009 at 10:50:26
Thanks for your help. I think I am about to give up. I added a pause command to the bottom of your suggested batch, to monitor what the batch file actually did when I ran it before it closed. With the ping command added to the end of the last line, as you had it, the batch file seemed to ignore the entire set of commands and skip to the pause at the end. No error messages, just nothing. No files copied. I then tried to add the ping command to the top of the batch file instead (I even extended the interval to some ungodly long value) to see if the batch file would hesitate before proceeding with the copy file routine. Here the batch file seems to just ignore the ping command and proceed to function as it had before. Lastly I asumed that perhaps the Nul at the end of the ping command should be spelled as Null. Making that change, the batch file still does not hesitate at all however it does create a little text file in the batch file root directory named Null that contains the following lines:

Pinging with 32 bytes of data:
Reply from bytes=32 time<1ms TTL=128
Ping statistics for
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

This doesn't seem like something that cannot be done which has left me feeling utterly frustrated. Looks like a picked a bad week to quit drinking.

Report •

September 10, 2009 at 12:23:32
You know what? I'm just going to throw in my method for adding delays

Step 1:
Make sleep.vbs

WScript.Sleep WScript.Arguments(0) * 1000

Step 2:
Replace that PING (which will never significantly delay your script as long as your TCP/IP stack remains intact) with the following line:

sleep.vbs 60

Report •

September 10, 2009 at 13:51:52
Ok, I created a file called sleep.vbs and placed it in the batch fille root directory.

Then I edited my batch file to this:

@echo off & setLocal EnableDELAYedExpansion
pushd "G:\GROUPS\color logics\FMData\FMDATA BU"
for /f "tokens=* delims= " %%a in ('dir /b/a-d "harbil*.dci"') do (copy "%%a" "G:\GROUPS\color logics\FMData\Harbil.dci" sleep.vbs 60)

Here is what it returned when I ran it:

The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
press any key to continue...

Report •

September 10, 2009 at 13:59:36
I'm a little confused on why it didn't seem to do anything, The only thing I can think is, in the origanal post you stated that you had text files, in the example batch file you posted the files had an extension of .dci

When I read the above I see
pushd which is changing the working directory to "G:\GROUPS\color logics\FMData\FMDATA BU" then it is running through that directory looking for files that are named Harbil(random).dci then when it finds a file that meets that, it should copy it to "G:\GROUPS\color logics\FMData\Harbil.dci" then wait 60 seconds.

The ping request may not be slowing things down since it is getting a reply from the local host. Try changing the ip that it is pinging to

Report •

September 10, 2009 at 14:04:45
When you copy and paste the above into a batch file, it needs to be formatted just like it looks in response 3
Instead of being on one line it will be multiple lines. Thats what the ( is doing after the "do" so it would be similar to

for ..... do (
Line with command
Line with command
Line with etc.....
) -this final one closes the for loop and tells it to go back and look for another file. This way you can do multiple commmands for each file that the for loop finds in your directory.

Report •

September 10, 2009 at 14:34:57
(copy "%%a" "G:\GROUPS\color logics\FMData\Harbil.dci" sleep.vbs 60)

You're missing an Enter there.

(copy "%%a" "G:\GROUPS\color logics\FMData\Harbil.dci" 
sleep.vbs 60)

Report •

September 11, 2009 at 06:03:36
Eureka! That did it. It all works like a charm now. This little routine is going to solve a big issue we are having in our lab. Gtaion and Razor2.3 thanks for your help!

Report •

Ask Question