Guest Jake R Posted February 7, 2008 Posted February 7, 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.
Guest Pegasus \(MVP\) Posted February 7, 2008 Posted February 7, 2008 Re: Copying folders with specific names (perhaps using ROBOCOPY) "Jake R" <jacobrich@gmail.com> wrote in message news:f9de32bb-9fd5-4f13-9988-dd5c0498c0a5@z17g2000hsg.googlegroups.com... >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. 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!" *.* )
Guest anygaard Posted August 27, 2008 Posted August 27, 2008 Re: Copying folders with specific names (perhaps using ROBOCOPY) I am trying to use this script, and am getting an error: ERROR 2 (0x00000002) Accessing Source Directory C:\%a\ The system cannot find the file specified. here is how I modified the script to my own use: @echo off setlocal EnableDelayedExpansion set Source=C:\docume~1\ set Target=C:\profiles\ dir /s /ad /b "%Source%*.*" | find /i "\desktop" > c:\dir.txt for /F "tokens=*" %%* in (c:\dir.txt) do ( set T1=%%* call set T2=!T1:%Source%=%Target%! robocopy /s "%%a" "!T2!" *.* ) I copied it from here, and only changed the source, target, and what it is finding, took out the echo, and it is not working. Any help would be greatly appreciated. -- anygaard ------------------------------------------------------------------------ anygaard's Profile: http://forums.techarena.in/members/anygaard.htm View this thread: http://forums.techarena.in/windows-server-help/910176.htm http://forums.techarena.in
Guest Pegasus \(MVP\) Posted August 28, 2008 Posted August 28, 2008 Re: Copying folders with specific names (perhaps using ROBOCOPY) Give yourself some eyes: Replace the line robocopy /s "%%a" "!T2!" *.* with echo robocopy /s "%%a" "!T2!" *.* and you will see immediately what's going on. Hint: Have a closer look at this line: for /F "tokens=*" %%* in (c:\dir.txt) do ( and ask yourself what name you assigned to your loop variable, i.e. the one preceded with %%. "anygaard" <anygaard.3etofd@DoNotSpam.com> wrote in message news:anygaard.3etofd@DoNotSpam.com... > > I am trying to use this script, and am getting an error: > > ERROR 2 (0x00000002) Accessing Source Directory C:\%a\ > The system cannot find the file specified. > > here is how I modified the script to my own use: > > @echo off > setlocal EnableDelayedExpansion > set Source=C:\docume~1\ > set Target=C:\profiles\ > dir /s /ad /b "%Source%*.*" | find /i "\desktop" > c:\dir.txt > > for /F "tokens=*" %%* in (c:\dir.txt) do ( > set T1=%%* > call set T2=!T1:%Source%=%Target%! > robocopy /s "%%a" "!T2!" *.* > ) > > I copied it from here, and only changed the source, target, and what it > is finding, took out the echo, and it is not working. Any help would be > greatly appreciated. > > > -- > anygaard > ------------------------------------------------------------------------ > anygaard's Profile: http://forums.techarena.in/members/anygaard.htm > View this thread: > http://forums.techarena.in/windows-server-help/910176.htm > > http://forums.techarena.in >
Recommended Posts