Solved

Robocopy syntax to copy folder and files

Posted on 2014-12-30
5
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 24

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 70

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 24

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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

705 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