I am using below script to append today's date and move files to an archive directory in following format:
XX-XXXX__2019-04-01.xlsx
XX-XXXX__2019-04-01.txt
Where XX-XXXX is a variable filename and 2019-04-01 in this example is today's date. I would now like to expand the archiving process to check the current date and also delete files older than 2 days - i.e. from 30 March and older. Any suggestions on how this can be achieved will be greatly appreciated, thanks!
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set DateTime=%%a
set Yr=%DateTime:~0,4%
set Mon=%DateTime:~4,2%
set Day=%DateTime:~6,2%
set Hr=%DateTime:~8,2%
set Min=%DateTime:~10,2%
for %%I in ("C:\Temp\Test_File\*.xlsx") do move "%%~I" "C:\Temp\Test_File\Archive\Processed\%%~nI__%Yr%-%Mon%-%Day%%%~xI"
for %%I in ("C:\Temp\Test_File\*.txt") do move "%%~I" "C:\Temp\Test_File\Archive\Logs\%%~nI__%Yr%-%Mon%-%Day%%%~xI"