Results 1 to 8 of 8

Thread: Copying folders with specific names (perhaps using ROBOCOPY)

  1. #1
    Jake R Guest

    Copying folders with specific names (perhaps using ROBOCOPY)

    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.

  2. #2
    Pegasus \(MVP\) Guest

    Re: Copying folders with specific names (perhaps using ROBOCOPY)

    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!" *.*
    )

  3. #3
    Join Date
    Aug 2008
    Posts
    1

    script issues

    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.

  4. #4
    Pegasus \(MVP\) Guest

    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 %%.

  5. #5
    Join Date
    Apr 2009
    Posts
    1
    >I'm trying to use robocopy to migrate some workstation profiles, settings, >and data but keep also coping the IE temp files and other unwanted files on >the new machines. Is robocopy capable of copying just wanted files from >the profiles and send them to a backup folder on the destination PC?

  6. #6
    Pegasus [MVP] Guest

    Re: Copying folders with specific names (perhaps using ROBOCOPY)

    Yes, it is. Have a look at the robocopy help files to see how it's done. It
    depends, of course, what you mean with "wanted files" . . .

  7. #7
    Join Date
    Sep 2010
    Posts
    1

    Re: Copying folders with specific names (perhaps using ROBOCOPY)

    Pegasus is not being very helpful in this post, and his original script was incorrect. Here is the corrected version:

    @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=*" %%a in (c:\dir.txt) do (
    set T1=%%a
    call set T2=!T1:%Source%=%Target%!
    echo robocopy /s "%%a" "!T2!" *.*
    )

    He put an asterisk instead of an 'a' in two places, but used the 'a' correctly in the last line. This is what he meant by 'your loop variable'.

  8. #8
    Join Date
    Oct 2010
    Posts
    1

    Re: Copying folders with specific names (perhaps using ROBOCOPY)

    Is there a way to perform this copy using a wildcard in the Find command?

    For example find all of the folders in the Source that have names beginning with "ABCD"?

Similar Threads

  1. Robocopy - Copying Permissions
    By john83 in forum Windows Software
    Replies: 2
    Last Post: 27-08-2010, 07:22 PM
  2. Folders are created with weird names
    By Shaan12 in forum Networking & Security
    Replies: 3
    Last Post: 05-12-2009, 06:31 AM
  3. Robocopy not copying top level NTFS Permissions
    By Crashball in forum Windows Server Help
    Replies: 1
    Last Post: 25-03-2009, 03:28 PM
  4. Replies: 5
    Last Post: 15-05-2007, 08:31 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,391,186.10954 seconds with 16 queries