简体   繁体   中英

.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. All in all, I want to keep every file, even if they are duplicates. TIA for any help!

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 /? , for /? , and if /? . Note you have to change directories for it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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