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.