I need to store these with the date in the filenames. They are different formats so, I think the best thing would be to store the filename with the date modified @fdate but it’s in a wierd format. Help?
forfiles -p “D:\path\logs” /D -10 /C “cmd /c if @isdir==FALSE ^0x22C:\Program^ Files\7-Zip\7z.exe^0x22 a -tzip ^0x22D:\path\logs\Archive\%today%_archive.zip^0x22 @path -sdel”
forfiles /P “D:\path\logs\Archive” /D -20 /C “cmd /c if @isdir==FALSE del /q @path”
forfiles @fdate format sucks, but forfiles does the date-math, batch’s date-math sucks, but it handles date format better. Here’s a sample.batch f/e ‘archive.bat’:
@echo off & setlocal
rem %1 is the filename submitted by forfiles when it invokes archive.bat
set x=%~t1
for /f “tokens=1-3 delims=/ ” %%a in (“%x%”) do set dt=%%c%%a%%b
“C:\Program^ Files\7-Zip\7z.exe” a -tzip “D:\path\logs\Archive\%dt%_archive.zip” %1
exit
::————— end batch
(I wasn’t sure what this does:
@path -sdel”
but it can be added to the batch if put in the correct syntax)
So:
forfiles /P “D:\path\logs” /D -10 /C “cmd /c if @isdir==FALSE archive.bat @file”