Updated: April 17, 2012
Applies To: Windows Vista, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows 8
Replaces files. If used with the /a option, replace adds new files to a directory instead of replacing existing files.
For examples of how to use this command, see Examples.
replace [<Drive1>:][<Path1>]<FileName> [<Drive2>:][<Path2>] [/a] [/p] [/r] [/w] replace [<Drive1>:][<Path1>]<FileName> [<Drive2>:][<Path2>] [/p] [/r] [/s] [/w] [/u]
Specifies the location and name of the source file or set of files. FileName is required, and can include wildcard characters (* and ?).
Specifies the location of the destination file. You cannot specify a file name for files you replace. If you do not specify a drive or path, replace uses the current drive and directory as the destination.
Adds new files to the destination directory instead of replacing existing files. You cannot use this command-line option with the /s or /u command-line option.
Prompts you for confirmation before replacing a destination file or adding a source file.
Replaces Read-only and unprotected files. If you attempt to replace a Read-only file, but you do not specify /r, an error results and stops the replacement operation.
Waits for you to insert a disk before the search for source files begins. If you do not specify /w, replace begins replacing or adding files immediately after you press ENTER.
Searches all subdirectories in the destination directory and replaces matching files. You cannot use /s with the /a command-line option. The replace command does not search subdirectories that are specified in Path1.
Replaces only those files on the destination directory that are older than those in the source directory. You cannot use /u with the /a command-line option.
Displays help at the command prompt.
As replace adds or replaces files, the file names are displayed on the screen. After replace is finished, a summary line is displayed in one of the following formats:
nnn files added nnn files replaced no file added no file replaced
If you are using floppy disks and you need to switch disks during the replace operation, you can specify the /w command-line option so that replace will wait for you to switch the disks.
You cannot use replace to update hidden files or system files.
The following table shows each exit code and a brief description of its meaning:
The replace command successfully replaced or added the files.
The replace command encountered an incorrect version of MS-DOS.
The replace command could not find the source files.
The replace command could not find the source or destination path.
The user does not have access to the files that you want to replace.
There is insufficient system memory to carry out the command.
The user used the wrong syntax on the command line.
You can use the ERRORLEVEL parameter on the if command line in a batch program to process exit codes that are returned by replace.