not quite programming.... creating .bat

Associate
Joined
2 Sep 2009
Posts
59
hi, im looking to create a .bat file where the logs are date and time stamped, as each time im logging the output, the file is getting overwritten, i'd like to keep a consistent log of the goings on.

going to be used on win 7.

thanks
 
Associate
Joined
14 May 2006
Posts
1,287
If I get you right, you want to append to a log file rather than creating a new one every time? If so, on your echo statements, use >> rather than a single > to append to the given file rather than recreate.
 
Associate
OP
Joined
2 Sep 2009
Posts
59
brill yes, did the job....but i have now got the log file (deleted and let it start afresh) logging it about 50 times when running it only once.

i did just take out /s/e and left in ..... /v/h/k/y

but still the same.
 
Associate
Joined
14 May 2006
Posts
1,287
brill yes, did the job....but i have now got the log file (deleted and let it start afresh) logging it about 50 times when running it only once.

i did just take out /s/e and left in ..... /v/h/k/y

but still the same.

What is executing your batch file? Have you got a loop in your batch file / can you post a copy of the code here?
 
Associate
Joined
14 May 2006
Posts
1,287
What about the content of the copy.bat file? I assume the contents you have posted is another batch file. Also, I have always used the 'call' keyword before calling another batch file but that might well not be needed in Win 7! I think without the call keyword it breaks the flow of the code and stops further code execution...might be wrong though!
 
Associate
Joined
14 May 2006
Posts
1,287
From that line, you want to print out to the log file the lines from the batch file? e.g. you'd want the log file to contain the following text lines:

xcopy /v/h/k/y D:\folder\source\"folder space" D:\folder\entry
D:\folder\copy.bat >> d:\folder\log.log
exit

If so, what you're actually do there is recursively calling the batch file so once it has finished copying the files, the batch file is executed again and therefore the files are copied again and it then calls itself again. This will probably be why the command window doesn't close as it would keep doing this until you manually closed the window (probably explains the multiple lines in the log file too!).

What information do you want to be stored in the log file?
 
Associate
OP
Joined
2 Sep 2009
Posts
59
ahhh ok, that makse sense.

either have multiple log files...having 00's is not an issue, or just date and time stamped each time its executed all within 1 file, whichever is easier. i DONT really need date and tme as the txt files will be time and date from windows anyway
 
Associate
Joined
14 May 2006
Posts
1,287
If you want to just note down when it is running (and the output of the xcopy) whilst keeping a single log file, do what Showboat put but add

echo Copy started at %date% %time%

to the file to log when it kicked off.
 
Back
Top Bottom