命令行移动某些类型的所有文件,没有覆盖/ y不工作

时间:2017-12-21 05:55:09

标签: windows cmd

cmd prompt命令出现问题:

for /r E:\ %f in (*.jpg) do @move "%f" "E:\jpg" /Y

此命令行无法正常工作。我试图将特定类型(即jpg)的外部驱动器上的所有文件移动到外部驱动器上的文件夹(E:/ jpg)

任何建议???

1. (with /Y)

Microsoft Windows [Version 10.0.16299.125]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\█████>for /r E:\ %f in (*.jpg) do @move "%f" "E:\jpg" /Y
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.

2. (without /Y)

Microsoft Windows [Version 10.0.16299.125]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\█████>for /r E:\ %f in (*.jpg) do @move "%f" "E:\jpg"
Overwrite E:\jpg\10255420_10200945699085042_5035519864603771578_n.jpg? (Yes/No/All): Yes
        1 file(s) moved.
Overwrite E:\jpg\10307411_10201163984180409_2977646430196181302_n.jpg? (Yes/No/All): 

1 个答案:

答案 0 :(得分:0)

对于移动文件,您可以使用robocopy而不是move,默认情况下它不会覆盖目标文件,除非它们具有不同的大小或时间戳,并处理多个文件。

您应该可以使用

进行一行

robocopy %cd% "E:\jpg" *.jpg /MOV

注意:cd是当前目录的环境变量

请参阅https://ss64.com/nt/robocopy.html