Solved

Robocopy to copy everything under a directory

Posted on 2013-05-20
10
823 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 69

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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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 69

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 69

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 69

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Free HD cloner 11 86
batch file problem 5 68
Robocopy Doesn't Retain Shared Folders After Copying 5 78
Windows Server Backup - listing of files that were backed up 26 105
Learn about cloud computing and its benefits for small business owners.
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 configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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