Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: xcopy directory wildcard use  (Read 50646 times)

0 Members and 1 Guest are viewing this topic.

johngotts

    Topic Starter


    Greenhorn

  • They look but don't see, hear but don't listen...
    xcopy directory wildcard use
    « on: March 18, 2010, 07:04:47 PM »
    When using xcopy, how specific can you be with wildcards when trying to specify which directories to search in?  If I have a directory containing subdirectories named "reports 2010, reports 2009, etc" and I want to search those for files to be copied, can I specify \reports*\   for example?

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: xcopy directory wildcard use
    « Reply #1 on: March 18, 2010, 07:30:51 PM »
    Good question.
    Have you searched in this forum database? There are some 100 topics just about what you can do with XCOPY.

    Here is just one of many that may provide the answer.
    http://www.computerhope.com/forum/index.php?topic=76290.0

    If you don't see anything close to what you want, come back here and get some more help.

    johngotts

      Topic Starter


      Greenhorn

    • They look but don't see, hear but don't listen...
      Re: xcopy directory wildcard use
      « Reply #2 on: March 22, 2010, 07:42:49 AM »
      Well, I searched as much as possible, it's kinda like looking for navy blue socks in the black sock drawer.

      Anyhow, here's the scenario.

      Folder 1 contains report folders by date (010208 Reports thru 013108 Reports) as an example.
      010208 Reports contains folders from the particular town where the reports were generated (town1 thru x)
      the town folders contains the actual (*.doc) reports to be copied.

      I was trying to specify:

      xcopy "c:\documents and settings\folder1\*reports\town1\*.doc" \newfolder /e/s/t   such that all existing report folders are searched for town1 folders and the *.doc files from each town folder are copied to a new folder.

      It doesn't seem to like the syntax /*reports/ and indicates no files can be found.


      ALAN_BR



        Hopeful

        Thanked: 5
        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: xcopy directory wildcard use
        « Reply #3 on: March 22, 2010, 09:51:55 AM »
        I suggest a test, one line at a time, until DIR finds something.
        Code: [Select]
        dir   "c:\documents and settings\folder1\*reports\town1\*.doc"
        dir   "c:\documents and settings\folder1\*reports\town1"
        dir   "c:\documents and settings\folder1\*reports"
        dir   "c:\documents and settings\folder1"
        dir   "c:\documents and settings"

        I think XCOPY should be able to copy anything that DIR can see.
        If DIR cannot see anything with
        "c:\documents and settings\folder1\*reports"
        but can see
        "c:\documents and settings\folder1"
        then perhaps there is no match for the folder "*reports"
        and you must alter your search parameter to fit reality

        Alan

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: xcopy directory wildcard use
        « Reply #4 on: March 22, 2010, 11:11:08 AM »
        Xcopy is one of the more complex utilities and the results can be quite unpredictable.

        Code: [Select]
        xcopy   "c:\documents and settings\folder1\*.doc" \newFolder /S /E /L

        This should hunt down all .doc files in the c:\documents and settings\folder1 directory tree and list them.

        Note: I used the /L switch as a whatif condition. This will give you a chance to see what will actually get copied. When you are satisified with the result, remove the /L switch. I also used the /S switch to check the subfolders and the /E switch for the empty folders. You may or may not need them. Check xcopy /? for all the gory details on the switches (there is a whole alphabet soup of them)

        Good luck.  8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        johngotts

          Topic Starter


          Greenhorn

        • They look but don't see, hear but don't listen...
          Re: xcopy directory wildcard use
          « Reply #5 on: March 24, 2010, 06:47:40 AM »
          Well, it appears there's a conflict when using searches that are non specific for the directories.  If I specify a specific "report" directory to search in, ie. "0102 reports", I can copy all day long.  Once I try to make it a search that is non-specific like "* reports", it won't search for the docs.  I guess I'm busted here.

          ALAN_BR



            Hopeful

            Thanked: 5
            • Computer: Specs
            • Experience: Experienced
            • OS: Windows 7
            Re: xcopy directory wildcard use
            « Reply #6 on: March 24, 2010, 11:17:26 AM »
            You are probably doing it wrong.

            What SPECIFIC folder are you interested in ?
            "Report 2010" as in your for post, or
            "2010 Reports" as in your latest post

            Does the folder name actually have exactly one embedded space ?

            I suggest you CD to the parent folder and issue the commands
            Code: [Select]
            CLS
            DIR   "c:\documents and settings\folder1\* Reports"
            If that finds the folder of interest, then try
            Code: [Select]
            xcopy "c:\documents and settings\folder1\* Reports\*.doc" \newFolder /S /E /L
            If you still have problems, I suggest a screen dump of the CMD.EXE display,
            showing both of the commands and the responses to the commands.

            To get a screen dump, right click on the CMD screen and "Select All",
            which changes the display to Black text on White Background,
            then Left Click and the display is restored to White on Black,
            and the contents are in your paste buffer.
            Then reply, and click the "Insert Code" button (Looks like a '#') and paste.
            That will ensure we can clearly see if there is a problem with too many spaces.

            Note, "*xyz" can include "* xyz", but not the other way round
            e.g.
            Code: [Select]
            C:\Documents and Settings\Dad>dir "\*ro* File*"
             Volume in drive C is ACER
             Volume Serial Number is EC16-8702

             Directory of C:\

            15/03/2010  17:17    <DIR>          Program Files
                           0 File(s)              0 bytes
                           1 Dir(s)   9,291,087,872 bytes free

            C:\Documents and Settings\Dad>dir "\*ro*File*"
             Volume in drive C is ACER
             Volume Serial Number is EC16-8702

             Directory of C:\

            15/03/2010  17:17    <DIR>          Program Files
                           0 File(s)              0 bytes
                           1 Dir(s)   9,291,087,872 bytes free

            C:\Documents and Settings\Dad>

            Alan

            Gew



              Newbie

              • Experience: Familiar
              • OS: Windows 10
              Re: xcopy directory wildcard use
              « Reply #7 on: August 07, 2020, 03:58:28 AM »
              Good info, guys!

              But is there any way to make XCOPY allow wildcards for directories?
              Obviously, the following command does not work:

              Code: [Select]
              C:\>xcopy folder* D:\I_WANT_THEM_HERE\

              0 File(s) copied

              In this scenario, I have a bounce of folders (folder1 folder2 folder3 folder_abc ...) and want all of them go be copied.
              Tried reading the documentation ("/?") but no syntax option seems to point me in the right direction.
              I could (of course) use a FOR loop, but isn't there any way using just the XCOPY.EXE ... ?

              nil

              • Global Moderator


              • Intermediate
              • Thanked: 15
                • Experience: Experienced
                • OS: Linux variant
                Re: xcopy directory wildcard use
                « Reply #8 on: August 07, 2020, 05:59:36 AM »
                Unfortunately in DOS the shell itself does not expand wildcards, it just passes them to the command. This means if you want to do anything fancy with a wildcard you need to explicitly expand it with for..in.

                https://www.computerhope.com/forhlp.htm#xp

                Take note of the /R option which recursively walks a directory structure.

                The following SO thread has an example of using for..in with xcopy:
                https://stackoverflow.com/a/35753046

                In your case (slightly different than this example) you might want to use /R, if you want the variable in your xcopy command to contain only a directory name, not a path to a specific file.

                Edit: CMD.EXE does parse wildcards, but does so differently for batch files and the command line -
                https://stackoverflow.com/a/4095133
                « Last Edit: August 07, 2020, 07:35:48 AM by nil »
                Do not communicate by sharing memory; instead, share memory by communicating.

                --Effective Go