Solved

Robocopy to copy everything under a directory

Posted on 2013-05-20
10
862 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 70

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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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 70

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 70

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 70

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
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…
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…

623 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