[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Move files and folders with ROBOCOPY in Windows 7

Posted on 2011-05-04
Medium Priority
Last Modified: 2012-05-11
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%

Question by:gquez
  • 4
  • 3
LVL 11

Expert Comment

ID: 35694074
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: http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_24502400.html

Author Comment

ID: 35694443
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.
LVL 11

Expert Comment

ID: 35694717
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.
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.


Author Comment

ID: 35699729
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.
LVL 11

Expert Comment

ID: 35701007
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.

Author Comment

ID: 35703673
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%
LVL 11

Accepted Solution

brutaldev earned 2000 total points
ID: 35709572
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.

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While Plesk offers many potential benefits to website administrators, including compatibility with Windows Server and other leading technologies, the company has also been working to differentiate it from other control panels for content management…
Your business may be under attack from a silent enemy that is hard to detect. It works stealthily in the shadows to access and exploit your critical business information, sensitive confidential data and intellectual property, for commercial gain. T…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question