Solved

Robocopy syntax to copy folder and files

Posted on 2014-12-30
5
239 Views
Last Modified: 2014-12-31
I need to copy or move a complete folder from one location to another. For example I need to copy or move the folder 2010 (F:\projects\2010) to \\fileserver\archives.

The syntax and examples I see for robocopy are all about copying the files in a folder to another folder, but I need to move the complete folder.  I have a feeling this is really simple and I will feel dumb, but I just can't quite get it.
0
Comment
Question by:gglollc
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:NVIT
ID: 40524807
To copy...
robocopy F:\projects\2010 \\fileserver\archives\2010

Open in new window


To move...
robocopy F:\projects\2010 \\fileserver\archives\2010 /move

Open in new window


If you're not familiar with how it works, be sure to test using the /nocopy switch
Also, the /LOG and /LOG+ switches are helpful for post examination.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40525214
By default, RoboCopy will only copy files. But all you need to do is to add /s (without empty subfolders) or /e (with empty subfolders).
robocopy F:\projects\2010 \\fileserver\archives /s
REM or
robocopy F:\projects\2010 \\fileserver\archives /s /move

Open in new window

But that will copy/move the contents of the 2010 folder into archives, the folder itself will not be created.
0
 

Author Comment

by:gglollc
ID: 40525817
Okay, thanks. So I will create the 2010 folder at the target first.
0
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
ID: 40525845
...I will create the 2010 folder at the target first
...or revise Qlemo's code, including the folder name:

robocopy F:\projects\2010 \\fileserver\archives\2010 /s
REM or
robocopy F:\projects\2010 \\fileserver\archives\2010 /s /move

Open in new window


If you have a bunch of folders to process, e.g. 2010, 2011, 2012...
make a .bat file with something like this. Note: Remove the ECHO to run it for real:

for /d %%a in (201?) do (
  ECHO robocopy F:\projects\%%a \\fileserver\archives\%%a /s /move
)

Open in new window

0
 

Author Comment

by:gglollc
ID: 40525987
Got it, thanks! Works great.
0

Featured Post

How does your email signature look on mobiles?

Do your employees use mobile devices to reply to emails? With mobile becoming increasingly important to the business world, it is in your best interest to make sure that your email signature looks great across all types of devices.

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

747 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

15 Experts available now in Live!

Get 1:1 Help Now