简体   繁体   English

.bat文件将多个文件从一个目录移动到另一个目录并重命名而不是覆盖

[英].bat file to move multiple files from one directory to another and rename instead of overwriting

Forgive me if this is a simple question, but I've been out of practice for a few years! 如果这是一个简单的问题,请原谅我,但是我已经几年没有练习了! I am creating a .bat file at work that will require me to move all files from one directory to another and if any conflicts arise, to add the date to the filename instead of overwriting it. 我正在创建一个.bat文件,该文件要求我将所有文件从一个目录移动到另一个目录,如果发生任何冲突,请将日期添加到文件名中而不是覆盖它。 All in all, I want to keep every file, even if they are duplicates. 总而言之,我想保留每个文件,即使它们是重复的。 TIA for any help! TIA有任何帮助!

MD "C:\NewFolder"

CD "%userprofile%\desktop"

For /f "delims=" %%A in ('dir /a-d /b "%userprofile%\desktop"') do If not exist C:\NewFolder\%%A (copy "%%A" "C:\NewFolder\%%A") Else copy "%%A" "C:\NewFolder\%%A%date:/=%"

It ugly but it works and should get you started. 它很丑陋,但是可以正常工作,应该可以让您入门。 See dir /? 看到dir /? , for /? for /? , and if /? if /? . Note you have to change directories for it to work. 请注意,您必须更改目录才能运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM