Tech Support > Microsoft Windows > Windows Server > Copying folders with specific names (perhaps using ROBOCOPY)
Copying folders with specific names (perhaps using ROBOCOPY)
Posted by Jake R on February 7th, 2008


I have a server with a fairly complex folder structure that needs
certain folders copied to another location.

Essentially, there are many folders and subfolders all over the D:
drive. In most of the subfolders there is a folder called "Archive".
Inside these Archive folders is the data that I need to move to
another server.

Does ROBOCOPY have a way of copying only folders with certain names? I
know how to copy files using wildcards to only copy certain filenames.

I am hoping that the same folder structure would be duplicated on the
destination server.

I have tried the following command, but of course it did not work (I
do not think that wildcards are allowed in folder names):

c:>robocopy \\source\d$\apps\arch*\ \\destination\d$\apps /s /e /z /
ipg:100 /r:1 /w:2

Any help would be greatly appreciated.

Thank you.

Posted by Pegasus \(MVP\) on February 7th, 2008



"Jake R" <jacobrich@gmail.com> wrote in message
news:f9de32bb-9fd5-4f13-9988-dd5c0498c0a5@z17g2000hsg.googlegroups.com...
You could do it with the batch file below. Please note this:
- The batch file will fail if your folder names include "poison" characters
such as &, %, ^, !, (, ).
- To activate the batch file, you must remove the word "echo" in
the robocopy line.

@echo off
setlocal EnableDelayedExpansion
set Source=D:\Source Folder\
set Target=\\server\share\dest folder\
dir /s /ad /b "%Source%*.*" | find /i "\archive" > c:\dir.txt

for /F "tokens=*" %%* in (c:\dir.txt) do (
set T1=%%*
call set T2=!T1:%Source%=%Target%!
echo robocopy /s "%%a" "!T2!" *.*
)




Similar Posts