Move files older than X days: Windows 11, 10, 8, 7

Move files older than X days: Windows 11, 10, 8, 7

You may need to move all files older than X days from one folder to another or delete them. Here we give you the command line to help you achieve this simple but tedious task in seconds.

What is the command syntax?

The command syntax is:
forfiles /p [source_path] /m *.* /s /d [-x_days] /c "cmd /c move @file [destination_path]"

Where:

  • source_path: the folder path from which you want to move all the files recursively.
  • x_days: the number of days.
  • destination_path: the folder path to where you want to move all the files. If replaced by >NUL, the files are just removed from the source folder.

This command can be saved in a .bat file and may be scheduled with other automated tasks.

Examples

  • forfiles /p C:\Processing /m *.* /s /d -360 /c "cmd /c move @file D:\Result"

It will move all the files from the folder located at C:\Processing, older than 360 days, to the destination folder located at D:\Result.

  • forfiles /p C:\Processing /m *.* /s /d -45 /c "cmd /c move @file >NUL"

It will remove all the files from the folder located at C:\Processing, older than 45 days.

any more questions about windows? check out our forum!
Around the same subject

Windows