Skip navigation

JSI Tip 0325 - The replace command.

Replace files in the destination directory with files from the source directory that have the same name. You can also use replace to add unique filenames to the destination directory.

replace \[drive1:\]\[path1\] filename \[drive2:\]\[path2\] \[/a\] \[/p\] \[/r\] \[/w\]
replace \[drive1:\]\[path1\] filename \[drive2:\]\[path2\] \[/p\] \[/r\] \[/s\] \[/w\] \[/u\]

 P a r a m e t e r   D e s c r i p t i o n 
 \[drive1:\]\[path1\] filename    Specifies the location and name of the source file or set of files. 
 \[drive2:\]\[path2\]    The destination directory. If this parameter is omitted, the current directory is used. 
 /a   Adds new files to the destination directory instead of replacing existing files. You cannot use this switch with the /s or /u switch.  
 /p   Prompts you for confirmation before replacing a destination file or adding a source file.  
 /r   Replaces read-only files as well as unprotected files. If you do not specify this switch but attempt to replace a read-only file, an error results and stops the replacement operation.  
 /s   Searches all subdirectories of the destination directory and replaces matching files. You cannot use the /s switch with the /a switch. The replace command does not search subdirectories specified in path1.  
 /w   Waits for you to insert a disk before replace begins to search for source files. If you do not specify /w, replace begins replacing or adding files immediately after you press ENTER.  
 /u   Replaces (updates) only those files on the destination directory that are older than those in the source directory. You cannot use the /u switch with the /a switch.  

As replace adds or replaces files, Windows NT displays their filenames on the screen. After the replace command is finished, Windows NT displays a summary line in one of the following formats:

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

You cannot use the replace command to update hidden files or system files. For information about changing hidden and system attributes, see the attrib command.

The following list shows each replace exit code:

 Value   D e s c r i p t i o n 
 0   Replace successfully replaced or added the files. 
 1   Replace encountered an incorrect version of MS-DOS. 
 2   Replace could not find the source files.  
 3   Replace could not find the source or destination path. 
 5   The user does not have access to the files 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. 

If several directories on drive D contain various versions of a file named JSI_DeskTop.htm, and "C:\Working Web\JSI_DeskTop.htm" contains a current version, typing:

replace "C:\Working Web\JSI_DeskTop.htm" D:\ /s

will update them all.

If you want to add all the new files in C:\Utilities to the backup directory C:\Utilities\BackUp, type:

replace c:\Utilities\*.* C:\Utilities\BackUp /a

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.