Solved

Robocopy syntax to copy folder and files

Posted on 2014-12-30
5
242 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 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 69

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to record audio from input sources to your PC ā€“ connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 ā€“ both 32 bit & 64.
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial sā€¦

840 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