The time may arise when you need to replace a file with a different version. For example, maybe you need to replace an HTML file with an updated version. If you’re only dealing with a few files, it’s generally easiest to use the COPY command to replace the file, or you could publish or save the file from the application you used to create it.

However, the COPY command isn’t the best solution when you’re replacing the same file in several locations or if you need to replace read-only files. Instead, use the REPLACE console command, which lets you replace one or more instances of a file with a single operation.

Using the REPLACE command
Say you need to replace a particular file that exists in several subdirectories under a particular folder. You can use REPLACE to replace all of them with one command.

Figure A
This image shows the REPLACE command being used to replace two instances of the file test.txt in all subdirectories of the c:\temp directory.

Figure A shows the REPLACE command being used to replace two copies of the file test.txt: one in c:\temp\Folder1 and the other in c:\temp\Folder2. The source file (test.txt) was located in the c:\ directory.

The /S switch accomplishes the recursive replacement. You can also use a handful of other switches with REPLACE to accomplish similar tasks. For example, you can use the /A switch to add new files to the destination directory or /U to update files that are older than the source files. To view the REPLACE syntax and its switches, open a console and enter REPLACE /?.