Move Files Older Than X Days Batch Scripting

I recently need to move files from one drive in Windows C: to another drive or volume E: due to space limitations. I created this batch file to move files from one directory to another directory older that X number of days. I moved all files older than 360 days. From an elevated command prompt:

——————————————————————

C:\Windows\System32>forfiles /p 
C:\Processing\Processed /m *.* /s /d -360 /c 
"cmd /c move @file E:\Processing"
       1 file(s) moved.
       1 file(s) moved.
       1 file(s) moved.
       1 file(s) moved.

——————————————————————

This will recurse through all of your subdirectories with the switch /s

You can save this file as a batch file so that it can be automatically run by task scheduler. Open notepad and paste the following contents:

——————————————————————

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

——————————————————————

Save as MoveFilesOlderThanXdays.bat. Just change the source and destination to your choice and enjoy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s