【发布时间】:2019-04-08 18:36:57
【问题描述】:
我需要将文件 test1.txt 从 C:\temp\ 移动到 D:\temp\(例如)。如果目标文件夹 D:\temp\ 中已经存在同名文件,我想将源文件移动并重命名为 test1.txt~。 是否可以进一步简化或优化脚本?
move c:\temp\test1.txt d:\temp\test1.txt~ || echo No | move /-Y c:\temp\test1.txt d:\temp\test1.txt
我需要一个用于 Windows 的类似 Linux 命令:
test -d DestinationFolder || mkdir -p DestinationFolder && mv -bfv SourceFile DestinationFolder
【问题讨论】:
-
使用
if exist检查目标文件是否已经存在。无论如何,如果新名称也已经存在怎么办?也看看this answer(用move替换copy应该没什么大不了的);而不是编号,您可以只附加~、~~等字符串(这在链接的答案中很容易实现) -
@aschipfl 我不仅需要“复制所有文件而不覆盖”我还需要“移动和重命名源文件”
标签: windows batch-file cmd