PDA

View Full Version : Batch program


Maximus
20 Sep 2004, 10:50pm
Hello veveryone,

I have a situation where a log file is generated throughout the day with the final log created at night between 11:00pm and 1:00am the next morning and is named according to the date it is for, ex040918 (ex((yy,mm,dd))) for Sept.18,2004, ex040930 for Sept. 30, 2004, ex041001 for Oct. 1, 2004. I need to create a batch program to run after 1:00am that will copy the log for the previous day to an existing directory. For example: ex040919 created 9/20/04 12:05am and ex040920 created 9/20/04 12:30am exist and at 1:00am the batch program has to copy ex040919 to the directory. Or ex040918 created 9/19/04 12:03am, ex040919 created 9/19/04 11:55pm and ex040920 created 12:20am 9/20/04. File ex040919 needs to be copied. Sorry for being long winded but my head is spinning.

Thank you for any help and guidance.

Black Hawk
21 Sep 2004, 8:36am
Is there any other files in the directory where the logs are? All I know is how to copy a specific type of file but not specific file name. If the log file is the only text file, you could try:
xcopy < source directory >\*.txt < destination directory > ("source directory' being the folder where the log is and "destination directory" being where you want the log to be copied to)

Example:
xcopy C:\Temp1\*.txt C:\Temp2
In a batch file I think it would be (make a new text document and save it with the extension as .bat or .cmd):
@ECHO OFF
xcopy C:\Temp1\*.txt C:\Temp2

I may be wrong since I've never really had to use batch files (or command line for that matter) that much. I suggest you test it on another machine or with a dummy file.

Maximus
21 Sep 2004, 2:07pm
The source directory is full of log files, of which, the current days log is modified throughout the day starting at 12:00am until between 11:00pm and 1:00am. The destination directory is full of the archived logs from the source directory. Unfortunately, I cannot copy the current days unfinished log over to the destination at the time the batch has to run, after 1:00am. What happens to the log before I get it and after I move it, happens off site and I have no control over it. So at 1:00am when the batch runs, the source has the previous and current days logs with possibly the same date. Only difference could be the name of the file.

Maximus
21 Sep 2004, 9:35pm
Hello,

Thanks for your help. I used an exe file to manipulate the date format, with a date offset, to resemble the names of the logs (ex040920.log), assign it to a variable and copy yesterdays log using the variable. It worked on all the tests I ran anyway.

Thanks again,
Maximus