0

I am trying to write a batch script to clean up old data in a compile directory. It must search in a certain head directory. There, it should delete files older than 7 days but ONLY in subfolders with a name that contains the word "compile", f.i. compile335, compile336...

This is what I came up with so far, but it is not working properly:

REM Remove files older than 7 days in compile directories of headDirectory
cd C:\headDirectory     
FOR /d /r . %%d IN (%Compile%\*) DO forfiles /p %%d /s /m *.* /d -7 /c "cmd /c Del @path"     

Can you tell me how I should change my script?

Edit:

Maybe my question was not clear enough. I Want something that does this:

forfiles -p "C:\Whatever\Compile1" -s -m *.* -d -7 -c "cmd /c del @path" 
forfiles -p "C:\Whatever\CompileFoo" -s -m *.* -d -7 -c "cmd /c del @path"
forfiles -p "C:\Whatever\CompileBar" -s -m *.* -d -7 -c "cmd /c del @path" 
forfiles -p "C:\Whatever\Compile23" -s -m *.* -d -7 -c "cmd /c del @path"

But in one single loop statement that tackles all compile folders in that directory, but leaves the other folders untouched.

Community
  • 1
  • 1
Apfelsaft23
  • 316
  • 2
  • 23

1 Answers1

0

Found it, it is

CD C:\HeadDIrectory

FOR /D /r %%G in ("*Compile*") DO forfiles -p %%G -s -m *.* -d -7 -c
"cmd /c del @path"

I made it quiet by calling it with a VB script:

Set WshShell = CreateObject("WScript.Shell" )  
WshShell.Run chr(34) & "path\mybatch.bat" & Chr(34), 0  
Set WshShell = Nothing

You guys know a more elegant way to keep it quiet?

Apfelsaft23
  • 316
  • 2
  • 23