0
I am in need of a batch that deletes specific files from a backup folder after the files are 30 days old (example).
I found this code but it uses an external program:
@echo off
move c:\TESTE\*.* d:\TESTE2\
exit
If you need to create directories first go by inserting the mkdir director_name commands
To delete old files I used this one:
@echo off
REM ///////////////////////////////////////////////////////////
REM // Define as variaveis de data //
REM ///////////////////////////////////////////////////////////
@Rem make var nowDay
FOR /F "TOKENS=1* DELIMS=/" %%A IN ('date/t') DO SET nowDay=%%A
REM ///////////////////////////////////////////////////////////
REM // Lista em log os arquivos encontrados //
REM ///////////////////////////////////////////////////////////
FORFILES /S /p C:\teste1\ /d -3 /C "CMD /C echo @FILE @FDATE" > C:\Logs\%nowDay%.log
REM ///////////////////////////////////////////////////////////
REM // Remove os arquivos encontrados //
REM ///////////////////////////////////////////////////////////
FORFILES /S /p C:\teste1\ /d -3 /c "CMD /C DEL @FILE /Q"
exit
There is a simpler way?
I accept yes, you can send me your tip.
– Eder Silva
The most commonly used way to solve this problem really is with
forfiles, but there are some interesting options in this answer in Soen Batch file to delete files Older than N days– David