Move files and folders with ROBOCOPY in Windows 7

I am trying to use the robocopy utility to move folders and files
from one location to another, just like you would do if you were to
cut and paste. I think I am close but there are still bugs in the script below.

Example of what I need:

I want to move "ALL" the folders and files from C:\Test1 to D:\Test2 without
deleting the source directory C:\Test1 and making sure I keep the date stamp
and any other settings associated with these files and folders, this would
also include empty directories as well. So if I were to manually go to the
C:\Test1 directory and do a select all, and then hit the (Ctrl + X), and then
go to the D:\Test2 directory and do a "Ctrl + V" all my files and folders will
be moved to the D:Test2 with the same settings like date stamp, etc..... and it
will also include empty directories. I need my script to do what I just described
above in my manual process.

Also, I understand the script below will leave the "placeholder.txt" in the C:\Test1 source
directory and I am fine with that as long as everything else in that directory goes to the new
destination D:\Test2.

When I run the script below the /minage:5 syntax is being ignored by empty folders and they
are being copied to the destination instead of being moved. Again, I just want my script to do a simple "CUT" from one location and "PASTE" to another location. Please help.....  
: Windows Batch File
SET src="C:\Test1"
SET dest="D:\Test2"
SET log="C:\Log\test-robocopy-log-file.log"

robocopy %src% %dest% /MOVE /E /R:10 /XF "placeholder.txt" /TEE /minage:5 /DCOPY:T /LOG+:%log%

Who is Participating?
brutaldevConnect With a Mentor Commented:
I have tested exactly what you have there and my previous post still stands true.

The directory structure will be copied but it or files within it will not be moved because they don't meet the MINAGE requirement. You should leave the setting at 5 and after a week it WILL move as long as files are in it are also older than 5 days.

Basically, if you have folders with files in them that are not old enough yet, the folder will get created in the destination anyway so cater for files that MAY get copied. Even though the documentation says MINAGE is for files it actually deals with folders the same way.

Your script is correct, change MINAGE to 1 and you'll see that most files and folders (if not all) will get moved. Use /V and check what the output is, it's very descriptive in telling you what was skipped.
MINAGE in your case will only move folder/files that are at least 5 days old. Check the date on the folders not getting moved.

Here is the question answered already as well:
gquezAuthor Commented:
I should of mentioned this before but when the folders are empty /minage is not looking at the date. In my case it is moving all empty folders regardless of date.
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

The documentation only mentions "file" age not "directory" age so directory will get moved regardless of this setting. Perhaps try a bigger setting like a year and see if they remain behind.
gquezAuthor Commented:
Try a bigger setting like year, how? I think we are getting closer, the following robocopy command moves all files and folders from one location to another just like cut and paste.

robocopy %src% %dest% /MOVE /E /R:10 /XF "placeholder.txt" /TEE /DCOPY:T /LOG+:%log%

Now, I just need help with using /minage or something else that will allow me to put in the command/script the following:

If a file in the source is older than 5 days move it to the destination, also, if a folder in the source is older than 5 days move that folder and all its files and sub folders to the destination.
With your requirement of only moving files/folders older than 5 days then /MINAGE:5 is exactly what you want.

The reason this does not seem to move certain directories (even empty) or files is probably because they're not 5 days old yet. By removing the /MINAGE option you can see that it moves everything, because nothing is being excluded.

Just to answer your question anyway, try to reduce (or increase) the number provided for MINAGE
EG: /MINAGE:1 will move everything that is older than 1 day. Change it to 365 and you'll see that hardly anything will move. This is expected behavior so you original command was right all along.

BONUS: To make testing this easier use /L which will only list the files that will move but not actually perform the move. Use /V to get much more detailed information including which files/folders where "skipped".

BONUS 2: Use /MT:n where n is the number of threads to use when copying, will make the process finish a lot quicker.
gquezAuthor Commented:
I tried /minage:365 and for what ever reason it is still copying the folder but without the files in the folders. Again, it copies the folder and it doesnt move them.

Example: I have C:/Test1/Folder1 and I have 5 files within the Folder1 folder. When I run the below command it only copies an empty folder named "Folder1" to the destination. Like you said before the /minage command is for files not directories. Is there similar syntax that will look at files and directories?

robocopy %src% %dest% /MOVE /E /R:10 /minage:365 /XF "placeholder.txt" /TEE /DCOPY:T /LOG+:%log%
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.