user3145218
user3145218

Reputation: 43

Batch file to move file older than 1 year to another folder

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"  
      )  
    )

Upvotes: 0

Views: 2081

Answers (1)

npocmaka
npocmaka

Reputation: 57252

 @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

Upvotes: 1

Related Questions