XXCOPY
[ Back to Table of Contents ] [ << ] [ >> ]

XXCOPY TECHNICAL BULLETIN #48


From:    Kan Yabumoto           tech@xxcopy.com
To:      XXCOPY user
Subject: The Source Base Directory
Date:    2009-11-16
===============================================================================

Introduction:

    During the long evolutionary path of XXCOPY, one enduring aspect
    of XXCOPY operations that has been the relationship between the
    source directory and the destination directory.

    Simply put, in a typical copy operation that involves subdirectories
    (with the /S switch), XXCOPY duplicates the directory structure
    (a.k.a. directory tree) of the source into the destination.
    
    In a two-directory operation (that involves a source directory and
    a destination directory), for any given path of a file or directory
    (possibly one or more level deep under the top-level directory) in
    the source, there exists one and only one path in the destination
    directory that corresponds its counterpart in the source.  This
    one-to-one relationship between the source and the destination is
    the backbone of the XXCOPY view of the system storage.

        One Source ===> One Destination

     ------------------------------------------------------------------
      The file-gathering functions (/SG and its variations) and the
      director-flattenning functions (/SX and its variations) are
      notable exceptions where the relationship between the source and
      the destination is "Many to One" rather than "One-to-One".
      (Currently, there is no such XXCOPY operations as "One-to-Many".)
      Even with such exceptional cases, the concept of the source base
      directory and the destination base directory still holds true.
     ------------------------------------------------------------------ 


The Base Directory:

    Let me first define the term, "Base Directory" in XXCOPY operations.
    A base directory is the longest part of either the source side or
    the destination side in an XXCOPY command where the user does not
    want any variation.  Therefore, by definition, a base directory cannot
    contain a wildcard character.  There is always one and only source
    base directory in a given XXCOPY operation and one and only one
    destination base directory (in a two-directory operation).

    Once the Source Base Directory is specified and the Destination Base
    Directory is also chosen, then, the two work as the anchor relationship
    that determines the rest of the subdirectories (tree structure). 
    
    Note that in XXCOPY operations, for the destinationspecifier, you can
    only furnish the path of a directory (not a filename nor a filename
    pattern).  Moreover, no wildcard character is allowed in the destination
    specifier, nor is the base directory marker (a double backslash) in
    the destination side.  Therefore, the the directory furnished by the user
    in the destination specifier is always the destination base directory.
    In other words, you have no choice on specifying the base directory
    for the destination.

    It is always helpful to see such relationships examining a few examples.


Simplest example:

      xxcopy C:\Windows\*.exe    D:\backup\C\Windows\  /S   // a simple one
      xxcopy C:\Windows\*\*.exe  D:\backup\C\Windows\       // equivalent

    The first command line above copies all files whose name ends with
    ".exe" in the source directory (C:\Windows\) and all of its subdirectories
    into the destination directory (D:\backup\C\Windows\).  The /S switch
    denotes that the operation includes the subdirectories.

    The second command line shown above is an exact replacement of the first
    one.  The two commands specify exactly the same thing and will perform
    exactly the same operation.  The use of ..\*\.. notation (that is placed 
    immediately to the left the last element (file name pattern) in the
    source specifier is equivalent to the /S switch (hence, it is omitted in
    the second example).

    So, the respective base directories are...

        source base directory       = C:\Windows\
        destination base directory  = D:\backup\C\Windows\

        The reason why we emphasize the idea of the base directory is that
        anything under the base directory in the source side will be faithfully
        duplicated in the destination side.  There is a clear one-on-one
        relationship between the source directory and the destination directory.
        The directory structure of the both sides will become identical when
        the copy operations take place.


Another example:

      xxcopy \\My_Server\C\Windows\   E:\backup\My_Server_C\  /BACKUP

        source base directory       = \\My_Server\C\Windows\
        destination base directory  = E:\backup\My_Server_C\

        The same rule applies with a UNC path. 


Using the Wild-Wildcard feature:

      xxcopy C:\Windows\Sys*\*.exe   D:\backup\C\Windows\  /BACKUP

        source base directory       = C:\Windows\
        destination base directory  = D:\backup\C\Windows\

        Here, unlike most other file management tools, XXCOPY allows you to
        sprincle wildcard characters (* and ?) anywhere in the source specifier
        for any number of times.  In this case, the source specifier can match
        both C:\Windows\System\ and C:\Windows\System32\ (and even
        C:\Windows\SysWOW64\ in 64-bit Windows environments).

        Remember the rule, the source base directory cannot have a wildcard
        in it.


A trick using the Wild-Wildcard:

    Consider one more example.  A long pathname is always an irritation to type.
    It's even more of a nuisance when the path contains an embedded space that
    forces you to use a pair of quotation marks (").

      xxcopy "C:\Program Files\Internet Explorer\iexplore.exe"  "D:\Program Files\Internet Explorer\"

        source base directory       = C:\Program Files\Internet Explorer\
        destination base directory  = D:\Program Files\Internet Explorer\

        We understand your hightened frustration when you find yourself re-typing
        much of the source path in the destination which is quite common.

   Let me show you a useful trick that alleviate the pain; the above command
   could be written as...

      xxcopy C:\Program?Files\Internet?Explorer\iexplore.exe  D:\
 
        The above command line replaced each of the space characters in the
        earlier command line with a question mark (?).  The benefit is twofold;
        1) you need not type the quotation marks (because no space characters)
        2) look at the destination specifier.

        source base directory       = C:\
        destination base directory  = D:\

        Although there is a small chance that the source specifier with a slightly
        increased liberty in the matching pattern (with the use of the wildcard
        characters), you can easily visually verify the result (when the number
        of files being selected in the operation is very small in a case like this).
        Note that the base directories for the source and that of the destination
        should be adjusted in a similar fashion.
 
    Let us indulge ourselves in pushing this idea further...

      With the use of asterisk (*) in lieu of question mark (?), you can save
      more keystrokes...

      xxcopy C:\Program*\I*\iexplore.exe  D:\      // works!!!
      xxcopy C:\p*\*\iex*.exe             D:\      // still works (but takes longer) 
      xxcopy C:\p*\*\iex*                 D:\      // No.  It included other files

        Of course, the shorter (more freedom given) to the matching pattern,
        the greater the chance of inclusion of undesired files becomes.  The
        second example above with the powerful ..\*\.. construct significantly
        widens the search area in the source directory.   The third one failed
        with the inclusion of an unexpected file as follows:
        
          C:\Program Files\Internet Explorer\en-US\iexplore.exe.mui

       Please note that this experiment was performed on a 32-bit Windows 7.
       In a 64-bit world, none of the three shown above were adequate.  There
       is a directory named C:\Program Files (x86)\ where the 32-bit version of
       Internet Explorer is kept.

       In short, although the technique of replacing the real pathname with
       a substituted pattern using wildcards is tempting, you should be aware
       of possible side effects.  For this reason, it may not be wise to use
       it in a batch file (where you should not be lazy in typing the full name). 


Enter the Base Directory Marker (\\):

    To take the spirit of the shortened source (and the destination) specifier
    without the side effect of inviting unwanted files into the party, we came
    up with a convenient feature that allows the user to specify explicitly the
    extent of the source base directory within a path string without the use
    of a wildcard character --- the use of a double-backslash sequence within
    the source specifier in the place of a regular (single) backslash.  We call
    it the "Base Directory Marker".  You are allowed to use it only once inside
    the source specifier. 

    Let me recall the original command line in question...
    
      xxcopy "C:\Program Files\Internet Explorer\iexplore.exe"  "D:\Program Files\Internet Explorer\"

        source base directory       = C:\Program Files\Internet Explorer\
        destination base directory  = D:\Program Files\Internet Explorer\
 
    
    Using the new Base Directory Marker, the command line above can be written as

      xxcopy "C:\\Program Files\Internet Explorer\iexplore.exe"  D:\

        source base directory       = C:\
        destination base directory  = D:\

        Note that there are consecutive backslashes immediately after the
        colon character (the drive letter specifier C:).

        Compare this to the trickery introduced earlier by the use of "?" in the
        place of space character (C:\Program?Files\Internet?Explorer\iexplore.exe).

        While the space characters left intact cannot allow you to drop the
        required quotation marks, the Source Base Directory Marker explicitly
        specifies without enlarging the freedom in matching path pattern otherwise
        unwanted.


Usage examples:

    A few more examples to clarify what's allowed.

      xxcopy C:\mydir\\projects\xxcopy\ver2975\debug\   D:\archive\  /BU

             // the Source Base Marker may be at any level


      xxcopy C:\mydir\\projects\xxcopy\v*\release\      D:\backup\   /BU

             // the right hand side of the source base directory marker may
             // contain a path with the Wild-wildcard syntax.


      xxcopy C:\mydir\\proj*\*\*.jpg                    D:\backup\    /BU

             // the position of the source base directory marker may coincide
             // with the implicit base directory termination (no effect, no harm).


      xxcopy C:\mydir\projects\xxcopy\\                  D:\backup\   /BU
        
             // another example of harmless, yet useless marker position


      xxcopy \\Kans_PC\C\\Documents*\*.jpg    C:\        /BU

            // This is from a working script actually in use by the author.


    Also, bad examples show you what to avoid.

      xxcopy C:\mydir\pro*\\xxcopy\ver2975\release\      D:\backup\   /BU

             // the left hand side of the source base directory marker must
             // not contain a wildcard character.  This is because the backslash
             // immediately left to the first wildcard character marks the end
             // of the source base directory path that cannot be overridden by
             // an explicit marker positioned to the right.


      xxcopy C:\mydir\\project\xxcopy\\ver2975\          D:\backup\   /BU

             // the source base directory marker can be used only once.


Avoid ambiguity with a UNC path:

    A source base marker is denoted by a double backslash with an additional
    backslash in place of a single backslash that normally separate one level
    of directory to the next.  Since a path that starts with a double backslash
    is an established syntactic rule in specifying a UNC path, you must not start
    with a double backslash notation when you want to use a root directory without
    an explicit drive letter.
    
    If the original path starts with a drive specifier (a letter followed by
    a colon), any double-backslash sequence is syntactically unambiguous.

       C:\mydir\       ===>   C:\\mydir\         // good

    However, if the path is a root directory without the drive specifier
    that starts with a single backslash, adding a backslash at the beginning
    would make it look like a UNC path which is unacceptable.

       \mydir\abc\     ===>   \\mydir\abc\       // BAD!!!  (avoid this)

    In such a case, you may either furnish the drive letter and colong to
    avoid the confusion with a UNC path.  Alternatively, you may add
    a "dot-backslash" sequence to avert the possible ambiguity. 

       \mydir\abc\     ===>   \.\\mydir\abc\     // good
       mydir\xyz\      ===>   .\\mydir\xyz\      // good





© Copyright 2016 Pixelab All rights reserved.

[ XXCOPY Home ] [ Table of Contents ] [ << ] [ >> ]

Join the XXCOPY group