Move files and folders with ROBOCOPY in Windows 7

Posted on 2011-05-04
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
    LVL 11

    Expert Comment

    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:

    Author Comment

    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

    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.

    Author Comment

    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

    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

    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

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
    Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
    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 viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now