0

I very new to batch scripting. My requirement is to move file from one folder to another folder which are older than 1 year. This should apply for all the sub folder of the source folder. Files which are coping to destination should create a folder of modification date of that file and copy into that folder. Here is the code i got from google search which will perform all the operation which I want except older than 1 year (means it is moving all files). Can someone help me how to move files which are older than 1 year.

 @echo off
    set "src=C:\test"   
    set "dest=C:\test"   
    for %%F in ("%src%\*") do (  
      for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (  
        if not exist "%dest%\%%C_%%A" mkdir "%dest%\%%C_%%A"  
        move "%%~fF" "%dest%\%%C_%%A"  
      )  
    )
npocmaka
  • 55,367
  • 18
  • 148
  • 187
user3145218
  • 43
  • 1
  • 7
  • Please see this question, just change 7 days to 365: "Batch file to delete files older than N days" (http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days?rq=1) – T-Heron Dec 13 '16 at 12:03

1 Answers1

1
 @echo off
    set "src=C:\test"   
    set "dest=C:\test"   
    for %%F in ("%src%\*") do (  
      for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (  
        if not exist "%dest%\%%C_%%A" mkdir "%dest%\%%C_%%A"
        forfiles /m "%%~fF" /c "cmd /c move 0x22%%~fF0x22 0x22%dest%\%%C_%%A0x22 " /d -365  
      )  
    )

more for forfiles

npocmaka
  • 55,367
  • 18
  • 148
  • 187