• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Robocopy syntax to copy folder and files

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
gglollc
Asked:
gglollc
  • 2
  • 2
1 Solution
 
NVITCommented:
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
 
QlemoC++ DeveloperCommented:
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
 
gglollcAuthor Commented:
Okay, thanks. So I will create the 2010 folder at the target first.
0
 
NVITCommented:
...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
 
gglollcAuthor Commented:
Got it, thanks! Works great.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now