Discussion Locked

Intelligent Archiving Batch Files

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Does anyone know of a way of making a batch file that uses the copy command and its ability to rename the destination file but in such a way that it renames the file according to a rule?

In particular I want to archive Event Logs. Copy the file C:\Winnt\System\Appevent.evt to a folder X:\Archive\Evntlogs\ and rename the file AppXXXX.evt where XXXX is a number 1 greater than the previous AppXXXX.evt (so the first Archive renames it App0001.evt, the next renames the new Appevent.evt to App0002.evt etc.).

This way I could run it as a Schedule and have a complete record of all events on the Server without having huge Event log files.

3 replies

by cdcents

While I'm not sure about names with numbers you can generate names with dates and times in them for a unique filename every time. To do this enter the foll in your batch file

setlocal
for /f "tokens=2 delims=/ " %%i in ('date /t') do set MONTH=%%i
for /f "tokens=3 delims=/ " %%i in ('date /t') do set DAY=%%i
for /f "tokens=4 delims=/ " %%i in ('date /t') do set YEAR=%%i

for /f "tokens=1 delims=: " %%i in ('time /t') do set HOUR=%%i
for /f "tokens=2 delims=: " %%i in ('time /t') do set MINUTE=%%i
for /f "tokens=3 delims=: " %%i in ('time /t') do set AMPM=%%i

set FILENAME=App%COMPUTERNAME%%YEAR%%MONTH%%DAY%%HOUR%%MINUTE%%AMPM%.evt
...other commands you may want to run..and finally

endlocal

Please note that I've put in to denote a line break. You do not need to use the AMPM variable if your machine is set for the 24 hour clock.

Hope this helps ....CD

by anthropic al

Yeh, cheers. I don't really understand those lines and I guess I should before I go using them but that's pretty much what I need.

This discussion is closed to new replies.