Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Robocopy to copy everything under a directory

Posted on 2013-05-20
10
Medium Priority
?
881 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
[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
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
"Any files you do not have backed up in at least two [other] places are files you do not care about."
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

660 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