如何在批处理文件中模拟“mv --no-clobber”?

时间:2012-05-09 01:57:47

标签: batch-file mv

顾名思义,--no-clobber命令的-n(或mv)标志(至少是Gnu版本)会导致命令失败,如果请求的移动会被覆盖现有文件。

如何在Windows批处理文件中模拟它?

(顺便说一句,预计的批处理文件是为了自动运行(即无人监管),因此任何需要提示人类用户进行许可的解决方案都已用完。)

谢谢!

1 个答案:

答案 0 :(得分:-1)

> MOVE /?
Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

  [drive:][path]filename1 Specifies the location and name of the file
                          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.
  [drive:][path]dirname1  Specifies the directory you want to rename.
  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.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.

> ECHO N | MOVE /-Y OLDFILE NEWFILE

可替换地:

IF NOT EXIST NEWFILE MOVE OLDFILE NEWFILE

结合多个文件的FOR循环。