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.
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!
Programming
- Delete old files batch script
- Batch delete file
- Delete file batch script
- Batch script to delete file older than 30 day [solved] > Forum - Windows
- Batch file for one current date in text file [solved] > Forum - Programming
- Batch script to delete subfolder from multiple subfolders [solved] > Forum - Windows 10
- Batch command for deleting both folders and contents order than 30 days [solved] > Forum - Windows 10
- Batch Script to Move files older than 30days > Forum - Windows
- Change Notepad++ background and foreground colors, dark mode
- Document list panel on Notepad++ is missing: how to enable?
- SQL Server diagram export: to another database
- 64 bit integers: C++, example
- Java Servlet Development Kit (JDSK) installation
- PHP IP address of a visitor