Take the 2-minute tour ×

As the name implies, the --no-clobber (or -n) flag of the mv command (at least the Gnu version) causes the command to fail if the requested move would have overwritten an existing file.

How can this be emulated in a Windows batch file?

(BTW, the projected batch file is intended to run automatically (i.e. unsupervised), so any solution that entails prompting a human user for permission is out.)


share|improve this question
add comment

1 Answer

up vote -1 down vote accepted
> MOVE /?
Moves files and renames files and directories.

To move one or more files:

To rename a directory:

                          or files you want to move.
  destination             Specifies the new location of the file. Destination
                          can consist of a drive letter and colon, a
                          directory name, or a combination. If you are moving
                          only one file, you can also include a filename if
                          you want to rename the file when you move it.
  dirname2                Specifies the new name of the directory.

  /Y                      Suppresses prompting to confirm you want to
                          overwrite an existing destination file.
  /-Y                     Causes prompting to confirm you want to overwrite
                          an existing destination file.

to prompt on overwrites unless MOVE command is being executed from
within a batch script.




Combined with a FOR loop for multiple files.

share|improve this answer
add comment

Your Answer


