Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a way to use robocopy to rotate log files. Currently I have a batch file using robocopy to copy files and log the results to a specified folder location. What I would like to do is keep 7 days and on the 8th day drop one off. Is this possible or should I create another batch file to do this and call it from the original batch file?

share|improve this question

If you are using a batch file, then it can delete older files in the log-files directory.

Here are two references:

ForFiles - delete old files, etc.
Describes using the forfiles utility for deleting older files.

batch file to delete files older than a specified date
Is a stackoverflow question that addresses your question here.

share|improve this answer
Thanks harrymc....I chose the use teh forfiles reference. It looks as if it will work well. – Wduncan Jul 14 '10 at 19:21
+1, I found out about this not too long ago and love it! I use it all over the place in my batch files. This is how I use it: forfiles /p "E:\Office Backups\Some Folder" /d -6 /c "CMD /C del @FILE" – Hondalex Aug 26 '10 at 20:27

You could use the following script:

set checklogcmd=robocopy /s /mov /create /minage:30 /r:0 /w:0
echo ### Checking Logfiles...
%checklogcmd% E:\LOGFILES E:\GARBAGE
rd E:\Garbage /s /q
share|improve this answer

What about syncing all files older than 30 days with an empty folder? I have used this with the purge command to delete with some success.

This example just delete all items from the target folder. With a little editing, it would do it based on a date.

robocopy.exe "B:\tb1\St-Cloud\EmptyFolder" "B:\St-Cloud\Daily\Fri" /E /PURGE

share|improve this answer

You could do something like this. Bit ugly, but it works. No real reason to use robocopy, as opposed to just a straight copy. This assumes your logfile is in a standard place, of course.

del logfile.7

robocopy logfile.6 logfile.7

robocopy logfile.5 logfile.6


robocopy logfile logfile.1

del logfile

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .