Replace command
Updated: 09/10/2024 by Computer Hope
The replace command replaces one file with another file.
Availability
Replace is an external command available in the following Microsoft operating systems.
- All Versions of MS-DOS
- Windows 95
- Windows 98
- Windows Me
- Windows NT
- Windows 2000
- Windows XP
- Windows Vista
- Windows 7
- Windows 8
- Windows 10
- Windows 11
Replace syntax
Renames a file/directory or files/directories.
REPLACE [drive1:][path1]filename [drive2:][path2] [/A] [/P] [/R] [/W] REPLACE [drive1:][path1]filename [drive2:][path2] [/P] [/R] [/S] [/W] [/U]
[drive1:][path1]filename | Specifies the source file or files. |
[drive2:][path2] | Specifies the directory where files are to be replaced. |
/A | Adds new files to destination directory. Cannot use with /S or /U switches. |
/P | Prompts for confirmation before replacing a file or adding a source file. |
/R | Replaces read-only files and unprotected files. |
/S | Replaces files in all subdirectories of the destination directory. Cannot use with the /A switch. |
/W | Waits for you to insert a disk before beginning. |
/U | Replaces (updates) only files that are older than source files. Cannot use with the /A switch. |
Replace examples
C:\>replace "C:\temp\*.txt" C:\test
In this example, each text file in the C:\test directory is replaced by a text file having the same file name from the C:\temp directory. If the files do not exist in test directory nothing would appear to happen because there is nothing to replace.