Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there anyway for me to quickly take an empty folder structure I have created on my desktop and copy it to 488 other folders all located on a network drive but in the same folder?

My primary difficulty with this is that I want the folder structure I have created to be placed in the sub folders of a networked folder. There are 488 folders where my structure must be copied to. They all contain additional folders and files themselves, which I do not want to have any effect on. Is there a way to set robocopy destination folder to a 1 level lower or deeper than the destination folder? Similar to /LEV:n but reversed essentially?

I have seen some postings mentioning recursion in what I believe to be are similar situations but I do not know how to execute a recursive function if that is possible.

share|improve this question
    
You should be able to use the /mir option with robocopy to mirror the directory tree. –  MaQleod Jan 30 '13 at 21:16
    
@MaQleod the "mir" flag does not do bi-directional replication. I know of only 1 tool that does this fairly well. Try looking at Unison. cis.upenn.edu/~bcpierce/unison –  TheCompWiz Jan 30 '13 at 21:18
    
@TheCompWiz: It didn't sound like he wanted bi-directional replication to me, it sounded like he wanted to take an empty directory tree on his PC and re-create it on a network drive. –  MaQleod Jan 30 '13 at 21:22
    
@MaQleod Please excuse me if I have misunderstood but I thought /mir would then also purge any data in the destination location that wasn't also in the source. I do not wish to delete anything from the destination. My source is a folder containing two more folders which contain five folders each. There are no files in these but the destination folder contains, pdfs and excel files that need to remain. Also my primary frustration is that the destination is 488 separate folders residing in one "customers" folder. Am I misunderstanding /mir? –  small3687 Jan 30 '13 at 21:23
    
@small3687 I'm glad to see that its working :) But one small suggest I have to do: Please don't use questions or answer for a simple "Thank you". The green check mark and comments are meant for this job. Also, its always good to delete obsolte comments so others will find the important information faster. –  nixda Jan 31 '13 at 20:25

1 Answer 1

up vote 2 down vote accepted

I am not quite sure if I understand every aspect of your question, but here we go.

Save this code to a CMD file and customize the source, destination and robocopy.exe path where destination means the root folder which contains your 488 subfolders.

@echo off
SET "source=C:\Users\zsmall\Desktop\Attachment Structure"
SET "dest=C:\Users\zsmall\Desktop\CustomTest"    
DIR /A:D /B %dest% > folders.txt    
for /f "delims=" %%G in (folders.txt) do (
C:\Windows\System32\robocopy.exe "%source%" "%dest%\%%G" /copy:DAT /E /W:2 /R:2 /MT:8
)
pause

What it does

  • lists all folders (no subfolders) from your destination folder and writes the names to a text file
  • loops through every folder in that list file
  • executes a robocopy command with the current folder as destination
    (source is always the same folder)
  • robocopy copies all folders, subfolders and files including data, attributes and timestamps

For information about the used parameters, look here:

Don't try to do it without saving the list first in a textfile. Or you may end up like me, who was creating thousands of subfolders with the same name.

share|improve this answer
    
Thank you so much for your help! This is the first time I have tried to do anything with a command line so I am a little confused and I haven't been able to get it to work just yet so a little help would be greatly appreciated. I have gotten it generate the the text file with the appropriate names of the folders but I haven't been able to get it to properly execute past that. I receive errors stating that no destination directory is specified. My code is as follows: –  small3687 Jan 31 '13 at 18:56
    
@echo off SET "source=C:\Users\zsmall\Desktop\Attachment Structure:\" SET "dest=C:\Users\zsmall\Desktop\CustomTest:\" DIR /A:D /B %C:\Users\zsmall\Desktop\CustomTest% > folders.txt for /f "delims=" %%G in (folders.txt) do ( C:\Windows\System32\robocopy.exe "%C:\Users\zsmall\Desktop\Attachment Structure:\%" "%C:\Users\zsmall\Desktop\CustomTest\%\%%G" /copy:DAT /E /W:2 /R:2 /MT:8 ) pause –  small3687 Jan 31 '13 at 18:57
    
Success! With some interesting notes. For some reason the MT:8 Parameter for multithreaded copying was producing an Error stating Invalid Parameter #7. To remedy this I simply tried deleting the line and running the command, which worked successfully. As you can see my source file was labeled Attachment Structure, which I wanted included when being copied to the destination files but it only included the folders inside that one. To solve that I simply made a second copy folder named Attachment Structure inside the original and the program behaved perfectly. Thanks so much :) –  small3687 Jan 31 '13 at 19:48
    
The MT:x parameter is not available for every robocopy version. Basically there are 3 main versions (XP016, XP026, XP027). This parameter was introduced with XP027. –  nixda Jan 31 '13 at 20:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.