I'm trying to write a script in batch file that do the following:
- Locate all folders with the name "Mdata" in "C:\Project".
- Delete all folders in "Mdata" that older than 30 days.
My code is:
@echo off
for /f "delims=" %%a in ('dir /b /s /a:d "C:\project\" ^|findstr /e /i "\Mdata"') do (
@echo "%%~a"
setlocal
set target=%%a
set days=-30
for /f "usebackq delims=" %%G in (
`forfiles /p "%target%" /c "cmd /c if /i @isdir == true echo @path" /d %days% 2^>nul`
) do rd /s /q "%%~G"
endlocal & exit /b
)
pause
The first task to locate all "Mdata" folders working well. but the delete dosen't work.