I am trying to delete .txt files which are 30 days old from a folder. Please note that this folder has other files types too, for example a subfolder with .bat files.
I am trying to use "forfiles /p %source% /s /d -30 /c "cmd /c del @file : date >= 30 days >NUL"
But it deletes all the files but not just .txt files. Please help
Following is my batch script:
"
@Echo off & Setlocal EnableDelayedExpansion
set "source=C:\Users\aditya.mudigonda\Desktop\Files\"
set "destination=C:\Users\aditya.mudigonda\Desktop\Files\script"
forfiles /p %source% /s /d -30 /c "cmd /c del @file : date >= 30 days >NUL"
Set "Found="
If exist %source%*.txt (
ROBOCOPY %source% %destination% /MAXAGE:1
echo "files received"
) Else (
echo "No files came in today"
)
for /f "delims=" %%A in ('
findstr /m "REJECTED" *.txt
') Do set "Found=!Found!,%%A"
If Defined Found (
Call :send %Found:~1%
) else (
echo All files accepted
del %destination%\*.txt
)
pause
Goto :Eof
:send
Echo %1 has been found rejected
if "%2" neq "" (shift & goto :send)
del %destination%\*.txt