robocopy command help

How to Use Robocopy Command to copy files previous dates

As a system admin, it often happens with a shared folder we need to take a backup of files that are created or modified in previous days. The example you want to take a backup copy or move of files that are created 7 days ago or and particular date. The best way to archive this task by using a command line or creating a batch file and automate the process.

Robocopy Help Command

robocopy /?

If we see help command we get a list of arguments we can use in robocopy in this example we focused on following arguments

/S this argument can be used for “copy Subdirectories, but not empty ones.”

/MINAGE: n Minimum file age will exclude files which is newer than any days or a specified date.

In our example, we say 7 days ago means the file and folders which is older than 7 days we need to copy and create a backup. So to archive this the command will be

robocopy [sourcefolder] [destinationfolder] *.* /S /MINAGE:days

our source folder in C:\tmp folder and want to move destination folder D:\tmp

robocopy c:\tmp\ d:\tmp *.* /S /MINAGE:7
robocopy copy files before 7 days

Same way if we want to copy files and folders which are created of modified last year before 31st December, same as above command only /MINAGE argument needs to modify with date format and the format is Year (4 digit) Month (2 digit) date (2 digit)

robocopy [sourcefolder] [destinationfolder] *.* /S /MINAGE:YYYYMMDD

And the command will use the date of 31st December 2018

robocopy c:\tmp\ d:\tmp *.* /S /MINAGE:20181231
robocopy copy files before date

Instead of copy, we want to move files with folders from Source to destination all we just need to add /MOVE argument which deletes files and folder from Source after copy. and command look like

For Days

robocopy c:\tmp\ d:\tmp *.* /S /MINAGE:7 /MOVE
robocopy move files before 7 days

For Date

robocopy c:\tmp\ d:\tmp *.* /S /MINAGE:20181231 /MOVE

*.* argument is used for any file name with any extension in can be changed as per our requirements for example if we want to copy only pdf files the command argument just change *.* to *.PDF

robocopy copy only pdf files