Replace


Applies To: Windows Vista,Windows Server 2008,Windows Server 2008 R2

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.

Syntax


Copy Code

replace [<Drive1>:][<Path1>]<FileName> [<Drive2>:][<Path2>] [/a] [/p] [/r] [/w]
replace [<Drive1>:][<Path1>]<FileName> [<Drive2>:][<Path2>] [/p] [/r] [/s] [/w] [/u]

Parameters

Parameter

Description

[<Drive1>:][<Path1>]<FileName>

Specifies the location and name of the source file or set of files. FileName is required, and can include wildcard characters (* and ?).

[<Drive2>:][<Path2>]

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.

/a

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.

/p

Prompts you for confirmation before replacing a destination file or adding a source file.

/r

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.

/w

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.

/s

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.

/u

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.

Remarks


Copy Code

nnn files added
nnn files replaced
no file added
no file replaced

Exit code

Description

0

The replace command successfully replaced or added the files.

1

The replace command encountered an incorrect version of MS-DOS.

2

The replace command could not find the source files.

3

The replace command could not find the source or destination path.

5

The user does not have access to the files that you want to replace.

8

There is insufficient system memory to carry out the command.

11

The user used the wrong syntax on the command line.

Note

You can use the ERRORLEVEL parameter on the if command line in a batch program to process exit codes that are returned by replace.

Examples

To update all the versions of a file named Phones.cli (which appear in multiple directories on drive C), with the latest version of the Phones.cli file from a floppy disk in drive A, type:

replace a:\phones.cli c:\ /s

Additional references

Command-Line Syntax Key