Archived from groups: alt.msdos.batch,microsoft.public.win2000.general (
More info?)
"Mostro" wrote in message
....snip
> the folder I want to copy has lots of directories inside of it as well as
> other types of files, oh, and some directories have lots of subdirectories
>
> when I try to xcopy I can either (depending on the switches) get the
> directories to copy or the root files but never both
>
> how can I, from the command line, copy a folder and all of its contents to
> another folder, period?
XCOPY will copy the contents of subfolders with the /s switch. Note
that if any files are "in use" during the XCOPY it will stall unless
you use the /c (continue on error) switch.
XCOPY recreates the Source folder structure on the Target, for example:
:: Example XCOPY line
xcopy C:\WORK\*.* E:\TARGET\BACKUP\*.* /s /c /e
This line copies all C:\WORK files and subfolders (including nested
subfolders) and their contents to E:\TARGET\BACKUP so that say, a
subfolder DATA such as C:\WORK\DATA becomes E:\TARGET\BACKUP\DATA
The /e switch is optional - it merely includes Empty subfolders.
Note that the /d (date dependent) switch is worthwhile considering:
:: Example XCOPY line with date dependency
xcopy C:\WORK\*.* E:\TARGET\BACKUP\*.* /s /c /e /d
This line works as before, except that only new or changed files are
copied, so if a file doesn't need copying (because current date/time
version exists on target), it will be skipped.
Note that:
:: Example XCOPY line with date dependency
xcopy C:\WORK\*.* E:\TARGET\BACKUP\*.* /s /c /e /d >NUL
will suppress the list of files copied and:
:: Example XCOPY line with date dependency
xcopy C:\WORK\*.* E:\TARGET\BACKUP\*.* /s /c /e /d >C:\LOGS\LOGFILE.TXT
will log the files copied to C:\LOGS\LOGFILE.TXT
Notes:
(a) The trailing \*.* wildcards prevent XCOPY asking whether the
specifications in its command line are files or folders.
(b) If you want to XCOPY to or from a remote machine, you'll need
to use the UNC path in the command line folder specification.
To find a UNC path to a file or folder:
(1) Open an MS-DOS window
(2) In the MS-DOS Window, type: REM+[Space] (but don't press Return)
(3) Open Windows Explorer
(4) Locate the file or folder in Network Neighborhood
(5) Left-click-hold file/folder, drag-and-drop it the MS-DOS Window
The MS-DOS window will have a REMark showing the full short form path.
The use of REM avoids accidental execution of any program file located
by this method.
If Explorer obscures the MS-DOS window at stage (5), hover
briefly over the Taskbar button for the MS-DOS window during the
drag-and-drop (don't release the mouse button) - the MS-DOS window
pops back into focus and you can easily drop the file/folder on it.
The same drag-and-drop technique can be used to find the full short
form path to a file or folder on the current machine.
--
William Allen
Free interactive Batch Course
http://www.allenware.com/icsw/icswidx.htm
For example Batch Files see:
http://www.allenware.com/find?BatchLibrary
Creative Technical Writing - Allen & Company: http://www.allenware.com/