Tuesday, 15 June 2010

Deleting log files which are a week old -



Deleting log files which are a week old -

i need help in writing script deletes "log" files 7 days old. going holiday, process done manually every week me. hence thinking create batch file , set in task scheduler run every week.

eg: there folder called "cache" , there 100 folders starting test-01,test-03,test-05

then within these test folders there logs files dated 120614.log,130614.log etc.. script should identify these log files under every folder , delete if 7 days old.

many thanks

you can utilize robocopy in peculiar way.

first utilize robocopy move week-old log files log folder tree temporary folder , after remove temporary folder. bonus 7zip moved log files before remove them.

robocopy c:\cache %temp%\erasecache /mov /minage:7 rmdir /s /q %temp%\erasecache how work

from robocopy /? learn:

usage :: robocopy source destination [file [file]...] [options]

/mov :: move files (delete source after copying). /minage:n :: minimum file age - exclude files newer n days/date.

and rmdir /?

rmdir [/s] [/q] [drive:]path

/s removes directories , files in specified directory in add-on directory itself. used remove directory tree. /q quiet mode, not inquire if ok remove directory tree /s

%temp% well-known environment variable holds directory current user has write permission

batch-file

No comments:

Post a Comment