Hi respree-ga,
Thanks for the interesting question; I've always wondered if this was
possible in windows but this gave me a reason to dig further than
normal :)
It turns out that xcopy (a copy utility included with Windows) is
actually incapable of copying files to a destination without the
subdirectories. This triggered a search for a utility that would be
able to achieve such a feat, and I ended up coming across this
program:
XCOPY - a Versatile File Management Utility---Boldly Extended Xcopy
http://www.xxcopy.com/
The following XXCopy Technical Bulletin exactly describes that
situation you (and no doubt countless others) have experienced:
" 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
D:\mydocs\MYFILE`Junk`Vote2000`gore`.DOC
D:\mydocs\MYFILE`Junk`Vote2000`bush`.DOC
D:\mydocs\MYFILE`Junk`Vote1996`dole`.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.
Examples:
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
"
http://www.xxcopy.com/xxcopy16.htm
You can download this freeware program from:
http://www.xxcopy.com/download/xxcopy.zip
The stipulations associated with this freeware can be found here:
http://www.xxcopy.com/index.html#tag_03
If you need to use this program for commercial use, XXCopy Pro
Licenses are also available:
http://www.xxcopy.com/index.html#tag_05
Well I can tell you I actually brought this into my own machine and
played around with it for a bit - I love it! Hopefully it will bring
you the same level of joy (or relief, whichever you prefer).
Search Strategy (Google):
windows xcopy tutorial (actually found in the sponsored links)
If you have any problems understanding the information above please
feel free to post a clarification and I will ensure a prompt response.
Cheers!
answerguru-ga |