How to wait to transfer some files after they are generated.

  • Thread starter Thread starter Don J
  • Start date Start date
D

Don J

I am using a batch file to call a program that runs a very long time. When
the program finishes I want to copy the results (some files) of the program
to another folder. How do I do it so that I don't try to make the transfer
before the files are generated. I am using XP Home.

Don J

-----------------------------------------------------
 
You can do the same in the batch file that calls the original program.

1. If the original program is DOS based, the batch file will wait until the
program exits before running the next line in the file which would be either
a copy or xcopy command to copy the file/s.

2. If the original program is a Windows based program you will probably
have to put in a wait loop until a condition exists before copying the
file/s. (I don't know if the batch file will wait automatically for a
Windows program to finish prior to executing the next line in the command
string since I have never tested this process.) The condition can be the
existence of the files. From the command interpreter prompt c:/> type IF /?
and see how to set up a loop (IF EXIST loop). You will also need to put a
label in front of the IF statement.

3. You can also create a batch file to automatically copy the files and put
it in the scheduled tasks queue at a specific time (say 1 hour after the
anticipated time of the end of the original program.
 
The program is Windows based. The files are not created by the program,
only modified by it. Presumably the only things that change from the
outside is the time and date. Is there anyway of using the time/date as the
trigger?

The program is intended to be called by the user, so Windows can be
immediately exited after the program is exited. I am using Windows XP Home.
Apparently XP Professional has ways of performing the transfer at the time
of exiting Windows. Do you know if XP Home can perform the transfer as a
result of Windows closing?


LVTravel said:
You can do the same in the batch file that calls the original program.

1. If the original program is DOS based, the batch file will wait until
the program exits before running the next line in the file which would be
either a copy or xcopy command to copy the file/s.

2. If the original program is a Windows based program you will
probably have to put in a wait loop until a condition exists before
copying the file/s. (I don't know if the batch file will wait
automatically for a Windows program to finish prior to executing the next
line in the command string since I have never tested this process.) The
condition can be the existence of the files. From the command interpreter
prompt c:/> type IF /? and see how to set up a loop (IF EXIST loop). You
will also need to put a label in front of the IF statement.

3. You can also create a batch file to automatically copy the files and
put it in the scheduled tasks queue at a specific time (say 1 hour after
the anticipated time of the end of the original program.
 
OK, just got home and tried something on my XP Home computer which is
connected to a peer to peer network. I did find out that the batch file
will wait until the Windows program ends before running the next line (I
tried it with Word and a backup batch file I had already created)
..
Start Notepad

Create a batch file with the original Windows program's path and executable
on the first line

The copy or xcopy command on the second and subsequent lines to copy the
files needed to copy.

On the last line type EXIT. (while not really necessary it ensures that
the command window closes)

Save the batch file as the program's name with a bat extension to the
desktop. You may have to tweak the properties of the command window to
ensure the program opens the way you want it to.

The example I tried is:

"C:\Program Files\Microsoft Office\Office\WINWORD.EXE"
"C:\Backup daily.bat"
EXIT

The quote marks need to be around the paths if there are any spaces in the
program name.

The contents of the daily.bat file referenced in the above example is:
(used to make daily backup of a few files changed each day)

@ECHO OFF
XCOPY "C:\DOCUMENTS AND SETTINGS\MYNAME\FAVORITES\*.*" V:\FAVORITES /E /I
/G /H /R /C /Y /D:4-10-05
XCOPY "C:\DOCUMENTS AND SETTINGS\MYNAME\DESKTOP\*.* V:\DESKTOP /E /I /G /H
/R /C /Y /D:4-10-05
XCOPY C:\DOWNLOAD\*.* U:\DOWNLOAD /E /I /G /H /R /C /Y /D:4-10-05
XCOPY D:\GRAPHICS\*.* U:\GRAPHICS /E /I /G /H /R /C /Y /D:4-10-05
XCOPY "D:\SONY PICTURES DOWNLOAD\*.*" U:\GRAPHICS /E /I /G /H /R /C /Y
/D:4-10-05
EXIT

Don J said:
The program is Windows based. The files are not created by the
program, only modified by it. Presumably the only things that change from
the outside is the time and date. Is there anyway of using the time/date
as the trigger?

The program is intended to be called by the user, so Windows can be
immediately exited after the program is exited. I am using Windows XP
Home. Apparently XP Professional has ways of performing the transfer at
the time of exiting Windows. Do you know if XP Home can perform the
transfer as a result of Windows closing?
 
Read other part of thread and just wanted to remind people about "Start /w
'command'", the "/w" instructs it to wait till "command" is finished before
executing next command (try "start/?" in cmd window). Seems that could be
used in one "controlling" batch file to call secondary batch files, waiting
as each finished before continuing?

Example might be

....
start /w copyfile.bat
....

or perhaps it needs to be

....
start /w call copyfile.bat
....
 
Back
Top