Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Robocopy to copy everything under a directory

Posted on 2013-05-20
10
Medium Priority
?
896 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 71

Accepted Solution

by:
Qlemo earned 2000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 71

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
 
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 71

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 71

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…
Suggested Courses

926 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