Solved

Robocopy to copy everything under a directory

Posted on 2013-05-20
10
777 Views
Last Modified: 2013-05-26
I have the following directory structure:

\\ftp\ftp storage\zk\data

I want robocopy to move all files and directories under data but leave the data folder.
I have tried both of these commands.  One deletes the Data directory.  The other copies everything but leaves empty directories behind in Data.  Is what I want to do possible with robocopy?

Deletes Data

ROBOCOPY.exe \\ftp\ftpstorage\zk\DAQDATA \\anotherlocation /E /MOVE /Z /R:3 /W:10 /LOG+:robolog.txt

Open in new window


Leaves empty directories

ROBOCOPY.exe \\ftp\ftpstorage\zk\DAQDATA \\anotherlocation /E /MOV /Z /R:3 /W:10 /LOG+:robolog.txt

Open in new window

0
Comment
Question by:dmwynne
10 Comments
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39181836
Use your first line and follow it up in your batch statement with a mkdir \\ftp\ftpstorage\zk\DAQDATA.
0
 
LVL 16

Expert Comment

by:uescomp
ID: 39181840
You can use the /MIR to basically mirror/duplicate the folder.  It makes an exact copy of whats in folder a to folder b
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39181921
/MIR won't move files. And by recreating the source folder all security and share settings are gone. So it is better to use the second line, which leaves empty folders, and then remove the subfolders:
pushd \\ftp\ftpstorage\zk\DAQDATA
ROBOCOPY.exe . \\anotherlocation /E /MOV /Z /R:3 /W:10 /LOG+:robolog.txt
rmdir /s/q . 2>nul
popd

Open in new window

The trick is to change into the root folder. You can't remove it then, but everything below will be.
Maybe even this works:
pushd \\ftp\ftpstorage\zk\DAQDATA
ROBOCOPY.exe . \\anotherlocation /E /MOVE /Z /R:3 /W:10 /LOG+:robolog.txt
popd

Open in new window

0
 
LVL 14

Author Comment

by:dmwynne
ID: 39182103
I'm not sure what pushd and popd are getting me here?  Are you saying to run robocopy from the remote server's folder I am copying from?
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39182171
Yes, exactly that. PushD will change drive and folder, like cd /d does, but it allows for using UNC paths (cd does not). And it stores the current working location on a stack.
PopD then resets the current working location of that prior to PushD.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 14

Author Comment

by:dmwynne
ID: 39182207
is it possible to run it from the machine I am moving the files to using pushd?
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39182769
No issue with that. Both locations (source and target) can be either local or remote.
0
 
LVL 14

Author Comment

by:dmwynne
ID: 39187489
So I think I have this working how I want.  So I understand this.  I am using pushd and moving into the Daqdata directory so that when robocopy tries to move daqdata it cannot since its in use.  This is what seems to be happening and is giving me the desired result in that its moving everything in daqdata and leaving daqdata because its in use.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39188195
Yes, that is exactly how it works.
0
 
LVL 14

Author Closing Comment

by:dmwynne
ID: 39197537
Worked great, thanks.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

757 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

22 Experts available now in Live!

Get 1:1 Help Now