Batch files can be created for customized tasks such as cleaning up older files from a system or copying files from one folder to another as backup. Some programming knowledge can prove useful when writing batch scripts. To write this script, the
forfiles command can be used. The batch script can be used to automatically delete files at the root of the directory specified. More than one directory can also be included in the batch file. The batch script can be scheduled to run with the scheduled tasks.
Issue
I would like to create a batch script which could copy files older than 30 days from one folder to another. I would also like it to delete the 30 days
old files from the source folder after copying them to the destination folder.
Solution
Try the following command to automatically delete files at the root of a directory. This command can be saved in a .bat file and scheduled with scheduled tasks.
forfiles /p "PATH" /s /d -30 /c "cmd /c del @file : date >= 30 days >NUL"
Change "PATH" with the path where you want the files to be deleted. If there are no spaces in the path you don't need the - symbol.
Note
Solved by Thomas
See also
Knowledge communities.
Published by
aakai1056 -
Latest update by Jeff