Jump back to the top page Jump back to the top page

 What is XXCOPY ?
 F A Q 
 About Us (Pixelab) 
On-Line Manual 
XXTB #001 
XXTB #002 
XXTB #003 
XXTB #004 
XXTB #005 
             . . .  


©2016 Copyright

 All rights reserved  
    [ Table of Contents ] [ Show as Detached ] [ >> ]


    From:    Kan Yabumoto           tech@xxcopy.com
    To:      XXCOPY user
    Subject: Gathering files into one directory using XXCOPY
    Date:    2000-09-14
    The trouble is...
      Do you know approximately how many files there are on your disk?
      Many people don't have a faintest idea.  But, if you find the XXCOPY
      utility useful at all, you should check the numbers every now and then.
      By the way, in my own modest machine, the C: drive has approximately
      150,000 files in 8,000 directories totaling about 20 GB.
      At any rate, we all face the same headache; too many files in too
      many directories.  Finding a file now becomes a project.  We try
      hard to come up with a better tool in our losing battle.
    Search and collect files into just one directory.
      In many cases, collecting certain files into a directory may save a
      lot of time.  For example, if you gather all Microsoft Word document
      (.DOC) files from the entire volume into just one subdirectory,
      browsing them and locating a particular file become much easier.
      That is what XXCOPY's /SX, /SG and their variations are for.
      The traditional way to do this is (don't type beyond the comment //... ),
         XCOPY  C:\*.doc  D:\mydocs\   /S       // using Microsoft's XCOPY
         XXCOPY C:\*.doc  D:\mydocs\   /S       // the same here with XXCOPY
           The /S switch makes the copy operation to recursively
           go inside subdirectories and copy all matching files.
           If subdirectories are not present in the destination,
           they will be created as needed.
             Note that the destination directory was deliberately
             chosen in a different drive in the examples above.
             Watch out if the destination is in the same volume...
               XCOPY  C:\*.doc  C:\mydocs\   /S       // a FATAL error
               XXCOPY C:\*.doc  C:\mydocs\   /S /CCY
             This is a classic case of the cyclic copy situation which
             Microsoft's XCOPY cannot handle.  Using /CCY, our XXCOPY
             allows you to specify the destination in the same volume.
             See XXTB #07 for detail.
         Although the files you wanted are all copied into the destination,
         the destination directory will inevitably have many subdirectories
         which makes your next step still very time-consuming.
    XXCOPY provides better solutions.
      XXCOPY has a better way to deal with the situation that avoids making
      subdirectories in the destination.  Of course, it is inevitable that
      many files share the same filename.  So, XXCOPY synthesizes new
      names when duplicate files are to be copied into the destination.
         XXCOPY C:\*.doc  D:\mydocs\   /SX
         XXCOPY C:\*.doc  D:\mydocs\   /SG
      Our original directory-flattening functions (/SX, /SL and /SR) combine
      the source directory path (only the distinguishing part) with the
      source filename to form a long filename which is always unique
      (and you can tell where the files are from).
          /SL     Flattens subdirectories, add-name-Left
          /SX     Flattens subdirectories, add-name-Middle
          /SR     Flattens subdirectories, add-name-Right
      By popular demand by XXCOPY users, we re-engineered the new file-gathering
      functions /SG and its variations which retain the original filename.
          /SG     same as /SGN (newest one and sorted by newness)
          /SGN    sorted, newest file first
          /SGO    sorted, oldest file first
          /SGF    unsorted, first come first served
          /SGNO   picks the newest file
          /SGOO   picks the oldest file
          /SGFO   picks the first file encountered
      That's a total of nine flavors to choose from!  Our favorite is /SGN
      which got the honor of being equivalent to its shorter version, /SG.
    The /SX (/SL or /SR) switch flattens a directory.
      To understand how these schemes work, it is easiest to actually
      run the command and take a look at the destination directory.
      Let us start with the directory-flattening functions.
        XXCOPY C:\*.doc  D:\mydocs\   /SX     // puts path in the middle
           The result would be
           D:\mydocs\MYFILE`My Documents`word`.DOC
         The four MYFILE.DOC files are collected from four directories.
         In this case, the backslash (directory name delimiter) is converted
         into a legal character which is infrequently used in filenames
         (default = back-apostrophe (`)).  (See below to select the directory
         name delimiter character other than the default character).
         The /SL and /SR variations respectively place the pathname part
         either at the left or at the right of the filename.  We like the
         /SX version the best among the three variations because the new
         filename starts like the original and the ending also remains
         the same so the Windows knows which application to associate
         the file when you double click the file icon.
    The /SG switch gathers files into a directory.
      All the file-gathering functions (/SG and its variations) work
      identically if there is only one file for a given filename.
      The switches with O (not zero, but Oh) at the end keep only one file
      Newest, Oldest, or the First one found) for a given filename.
      On the other hand, other /SG functions have to gather all files
      with the same filename into one directory.  Therefore, we need to
      synthesize the filenames for the duplicates.  XXCOPY simply adds
      a "middle name" to the filename.  For example,
         XXCOPY C:\*.doc  D:\mydocs\   /SG     // sort, newest file first
           The result would be
           D:\mydocs\MYFILE.DOC                // the newest file
           D:\mydocs\MYFILE.0001.DOC           // 2nd newest
           D:\mydocs\MYFILE.0002.DOC           // 3rd newest
           D:\mydocs\MYFILE.0003.DOC           // 4th newest
      These functions are fun to play with.
      For example, just see how many .JPG (image) files are on your system
          XXCOPY C:\*.jpg  C:\temp\   /SG /CCY
          You may be surprised how much space is tied up with them.
          This particular example may become your favorite tool to
          snoop your children's computer for questionable pictures!!!
    Reversal of flattening = rebuilding the tree.
      With regard to the difference between /SX and /SG, for a casual and
      temporary usage, the /SG switch seems easier for most people.  The
      most important difference of the two approaches is that the /SX (and
      also /SL and /SR) switch synthesizes the new filename without losing
      the origin of the file.  As a matter of fact, XXCOPY provides the
      following three switches which allow you to rebuild the original
      directory structure from the destination (flattened) directory.
          /SLR   Rebuild the original directory from directory made by /SL
          /SXR   Rebuild the original directory from directory made by /SX
          /SRR   Rebuild the original directory from directory made by /SR
          Note that these switch must match the way the flattened directory
          was made.  For example if you flatten a directory using /SL, you
          must use /SLR and so on.  Also, the directory name delimiter
          character must be consistent between the flattening and the
          rebuilding steps.
               XXCOPY C:\word\*.doc  D:\mydocs\   /SX        // flattens
               XXCOPY D:\mydocs\     C:\word2\    /SXR       // rebuilds
             The ultimate destination directory (C:\word2\) would contain
             the same files and subdirectories as in the above two steps
             when you run the following command which copies the files
             to the destination directly.
               XXCOPY C:\word\*.doc  C:\word2\    /S
    About the directory name delimiter character.
      The directory name delimiter can be any legal non-alphabetic,
      non-blank character.  The following line lists all such characters:
              !  #  $  %  &  '  (  )  -  .  @  ^  _  `  {  }  ~
          Since many of them are frequently used in common English usage
          and therefore likely to appear in filename, the choice for the
          default delimiter character (the back-apostrophe character `)
          was chosen.  The next good candidate is probably the caret symbol (^).
          The trouble here is that the character used as the substitute for
          the backslash character must be a legal character for a filename,
          therefore, it is inevitable that the chosen delimiter may already
          be a part of existing filename.  In such unfortunate cases, the
          directory name which would be rebuilt from the synthesized name
          would not be identical to the original path, a small inconvenience.
    Final note.
      Lastly, let me remind you that gathering files into a directory
      is nice, but that contributes to yet more redundant files.  So, make
      sure that you remove all the files you collected for a temporary
      purpose as soon as you are done with them.  One way to deal with
      it is to always use the same one directory for temporary jobs.
    [ Table of Contents ] [ Show as Detached ] [ >> ]