DOS Wildcard for directory

Posted on 2012-08-23
Last Modified: 2014-05-22
I am looking for the proper syntax to use so that the xcopy command will skip over the * directory as it can have different names. Like:

XCOPY C:\temp /E /EXCLUDE:\inetpub\wwwroot\*\subdir
Question by:w_wagner
    LVL 51

    Expert Comment

    by:Bill Prew
    Well, a couple of issues with that. First the /EXCLUDE option actually wants the name of a text file, and in the text file each line contains a string that if it matches any part of the file being copied it will be skipped.  But wildcards are not allowed in this exclude text file.

    What you could do is do a few commands in a BAT file before the XCOPY that would build the text file of all folders that matched the template you posted above.  It can't be done with a simple wildcard like you tried, they aren't allowed in the middle of a path like that, but with a few more commands we could build the list of the directories you want to exclude.  Could that work for you, a BAT file?

    LVL 5

    Expert Comment

    Are you trying to explicitly exclude the "subdir" one level deep from wwwroot?  Is the "subdir" name somewhat unique?  I believe that the /exclude param of xcopy expects a file that contains patterns to match; from the help:

    Specifies a list of files containing strings.  Each string
    should be in a separate line in the files.  When any of the
    strings match any part of the absolute path of the file to be
    copied, that file will be excluded from being copied.  For
    example, specifying a string like \obj\ or .obj will exclude
    all files underneath the directory obj or all files with the
    .obj extension respectively.

    So you may want to use something like \subdir\ if that would be unique.  It also looks like you're missing the param to specify where you're copying C:\temp to?  Best of luck!
    LVL 51

    Accepted Solution

    Here's an example of the BAT script approach I was suggesting.

    @echo off
    if exist "%TEMP%\_exclude_.txt" del "%TEMP%\_exclude_.txt"
    for /D %%A in ("c:\temp\inetpub\wwwroot\*") do if exist "%%~A\subdir\" echo %%~A\subdir\>>"%TEMP%\_exclude_.txt"
    xcopy C:\temp D:\dest /E /EXCLUDE:"%TEMP%\_exclude_.txt"

    Open in new window


    Author Comment

    Thanks. I'll give your suggetions a try.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now