Ferret32 Super Finder Want to view and find data, search and Auto Browse your own Netscape Bookmarks,store and find passwords, or just multi-thread search the Web? You can't beat Ferret 32!
Organize your life, store and find anything about everything one simple tool!
Search This Site The Web

Get a Search Engine For Your Web Site

Xcopy--Examples


XCOPY runs in the "Dos" shell. It is a very useful copy command rich in features. The best way to understand this power is to look at an example.

xcopy e:\salkow\*.* Z:\Projects\MonoLake\0_Conversion_IPT\HardWare\Hw_Eng\Conversion\salkow /s/d

The above command copies all the files that re newer than the desination files from the local directory e:\salkow\ including all the folders therein to the remote mapped server Z: into the desired folder:
Projects\MonoLake\0_Conversion_IPT\HardWare\Hw_Eng\Conversion\salkow

This is just like an incremental backup that does updates only the newer and changed documents

.

To copy all the files and subdirectories (including any empty subdirectories) from the disk in drive A to the disk in drive B:


xcopy a: b: /s /e
To include any system or hidden files in the previous example, add the /h switch:
xcopy a: b: /s /e /h

To update files in the REPORTS directory with the files in the directory RAWDATA that have changed since December 29, 1993

xcopy \rawdata \reports /d:12-29-93

To update all the files that exist on \REPORTS in the previous example, regardless of date, type xcopy \rawdata \reports /u

To obtain only a list of the files that would be copied for the previous command, without copying the files, type xcopy \rawdata \reports /d:12-29-93 /l >xcopy.out

The file XCOPY.OUT lists every file that would be copied. To copy the \CUSTOMER directory and all subdirectories, including empty directories, to the directory \PUBLIC\ADDRESS on network drive H: and retain the read-only attribute, while being prompted when a new file will be created on H:, type

xcopy \customer h:\public\address /s /e /k /p

To issue the previous command and ensure xcopy creates the directory \ADDRESS if it does not exist, without prompting, add the /i switch:


xcopy \customer h:\public\address /s /e /k /p /i

You can create a batch program to perform xcopy operations and use the batch if command to process the exit code in case an error occurs. For example, the following batch program uses replaceable parameters for the xcopy source and destination parameters:



@echo off
rem COPYIT.BAT transfers all files in all subdirectories of
rem the source drive or directory (%1) to the destination
rem drive or directory (%2)

xcopy %1 %2 /s /e

if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit

:lowmemory
echo Insufficient memory to copy files or
echo invalid drive or command-line syntax.
goto exit

:abort
echo You pressed CTRL+C to end the copy operation.
goto exit

:exit

To use this batch program to copy all files in the C:\PRGMCODE directory and its subdirectories to drive B, type the following command:

copyit c:\prgmcode b:

The command interpreter substitutes C:\PRGMCODE for %1 and B: for %2, then uses xcopy with the /e and /s switches. If xcopy encounters an error, the batch program reads the exit code and goes to the label indicated in the appropriate if errorlevel statement. Windows NT displays the appropriate message and exits from the batch program.



Xcopy

Copies files and directories, including subdirectories. xcopy source [destination] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/d[:date]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [/a|/m] [/n] [/exclude:filename] [/z]

Parameters
source
Specifies the location and names of the files you want to copy. Source must include either a drive or a path. destination
Specifies the destination of the files you want to copy. Destination can include a drive letter and colon, a directory name, a filename, or a combination.
/w
Displays the following message and waits for your response before starting to copy files:

Press any key to begin copying file(s)
/p
Prompts you to confirm whether you want to create each destination file. /c
Ignores errors.
/v
Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files. This switch is ignored because the functionality is inherent to the Windows NT operating system. The switch is accepted only for compatibility with previous versions of MS-DOS.
/q
Supresses display of xcopy messages.
/f
Displays source and destination filenames while copying.
/l
Does not copy files, only displays (lists) files that would be copied.
/d[:date]
Copies only source files changed on or after the specified date. If the date value is missing, xcopy copies all source files that are newer than the time of existing destination files. This option allows you to update only files that have changed. If you specify a date, use a "-" as the separator rather than a "/" so that the date is not interpreted as another parameter.
/u
Copies (updates) only files from source that exist on destination.
/i
If source is a directory or contains wildcards, and destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory then copies all specified files into the new directory. By default, xcopy will prompt you to specify whether destination is a file or directory.
/s
Copies directories and subdirectories, unless they are empty. If you omit this switch, xcopy works within a single directory.

/e
Copies all subdirectories, even if they are empty. Used with the /s and /t switches. /t
Copies only subdirectory structure (tree), not files. To copy empty directories, you must include the /e switch.
/k
Copies files and retains the read-only attribute on destination files if present on the source files. By default, the read-only attribute is removed.
/r
Copies over read-only files.
/h
Copies files with the hidden and system file attributes. Xcopy will not copy hidden or system files by default.
/a
Copies only source files that have their archive file attributes set. This switch does not modify the archive file attribute of the source file. For information about how to set the archive file attribute, see the attrib command.
/m
Copies source files that have their archive file attributes set. Unlike the /a switch, the /m switch turns off archive file attributes in the files specified in source. For information about how to set the archive file attribute, see the attrib command.
/n

Copies using NTFS short file or directory names. This switch is required when copying files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (8.3) is required on the destination volume. The destination file system may be FAT or NTFS.


/exclude:filename

Excludes the files listed in the specified file from the copy operation. The exclusion file can have a list of exclusion patterns (one per line, no wild card characters are supported). If any exclusion pattern in the file matches any part of the path of a subject file, that file is not copied.


/z

Copies over a network in restartable mode.



Home Page Previous  Next Ferret's Home Page