I'm building batch files to (1) move directories older than 120 days to an archive location and (2) then eventually delete those folders from the archive location when they are 4 years old.
The names of the directories are in CCYYMM format (201601). The business rule is to move/delete based on the date in the directory name, not the modify or create date.
This is similar to Batch file logic to delete files based on date in filename, but since my scenario is for directories, not files, not certain if this would work, or how to modify for directories. The FOR command only appears to work for files(?)
Is there a method to loop through directories and perform a move or rmdir command in a batch file, comparing the month/year in the name to current month/year?
I did find that FORFILE works for directories based on modified date, but requirements are to use directory name.
Thanks for your consideration!
Edit 20160817
Since the directories are year/month labeled (201601 for January 2016), I'm taking the current year month (201608) and subtracting the directory value. For example 201608 - 201601 = 7. Then the batch would move any folder that has a difference of 4 or greater to meet the business requirements, using the FOR /D and only looking at directories beginning with 2:
@echo off
setlocal EnableDelayedExpansion
SET tempDATE=%DATE:~10,4%%DATE:~4,2%
for /d %%a in ("2*") do (
set /a numberOld=tempDATE - %%a
if !numberOld! geq 4 move /Y %%a ArchiveFolder
)
Using the same type of logic, I'm using 400 as the test value for the remove/delete directory script.
Appreciate everyone's insight.