I have a task about creating a script to move files in a folder to follow the last modified date. I have done the task with the below script:
@echo off
set "source=C:\Users\xxxxx\test-bash\ARCHIVE"
for %%F in ("%source%\*") do (
for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
if not exist "%source%\%%C_%%A" mkdir "%source%\%%C_%%A"
move "%%~fF" "%source%\%%C_%%A"
)
)
pause
The issue happens when I try to move the files only before the current time 2 months. Example: If the current time is: 20/4/2021, only files from backward 1/2021 will be moved to folder. I have tried to set %%A and %%C to handle some case but It can't run properly, like this:
set /a file_year = %%C
Could please explain why I can't assign this value? Thank you so much!