Solved i need to delete log files which is older than 7 days.

July 25, 2012 at 05:40:49
Specs: Windows 7
i need to delete log files which is older than 7 days. Each day the log will be created as on the present day as the folder name. eg)20120725 for todays folder. pls help.

See More: i need to delete log files which is older than 7 days.

Report •


✔ Best Answer
July 29, 2012 at 06:10:02
Well, seeing as we keep talking about FORFILES without actually providing an example:
forfiles /d -7 /c "cmd /c @del @path"

How To Ask Questions The Smart Way



#1
July 25, 2012 at 19:18:09
here is recycled script from another post:
@echo off & setlocal enabledelayedexpansion
:this creates the vbs one-liner each time the batch is run...
>da20.vbs echo wscript.stdout.writeline(dateadd("d",date,wscript.arguments(0))
:here's your target, flexible for down-the-road
set add=-7
:alternate sometimes needed: for /f %%a in ('cscript /nologo da20.vbs %add%') do
for /f %%a in ('da20.vbs %add%') do call :format %%a
for /f %%a in ('dir /b /a:d /o:n') do (
if %%a geq %out% goto :eof
echo del /q %%a
echo rd %%a
)
goto :eof

:format
for /f "tokens=/" %%a in ("%1") do (
set out=%%c
set x=0%%a
set x=!x:~-2!
set out=!out!!x!
set x=0%%b
set x=!x:~-2!
set out=!out!!x!
:end


Report •

#2
July 26, 2012 at 09:53:24
This sounds like something FORFILES was designed for.

How To Ask Questions The Smart Way


Report •

#3
July 27, 2012 at 17:17:09
I keep forgetting about that command. I have a win-7 system, but I use xp for my working base. I was just wondering to myself when MS would get around to better handling of date-math, and I guess they already have.

Report •

Related Solutions

#4
July 28, 2012 at 17:37:06
Yeah FORFILES is actually pretty useful, especially for applications like this.

Tony


Report •

#5
July 29, 2012 at 06:10:02
✔ Best Answer
Well, seeing as we keep talking about FORFILES without actually providing an example:
forfiles /d -7 /c "cmd /c @del @path"

How To Ask Questions The Smart Way


Report •


Ask Question