简体   繁体   中英

Move files in subfolders to a folder and rename windows prompt

I have almost the final command line, but I need the rename part of it, to reach the goal I want I have this:

for /f “tokens=*” %a in ('dir /b /s /a-d') do @copy “%a” “C:\\YourFolder” /y

and it works fine, but in my case I have tons of folders with only one file on each one, this file has the same name file.ext, so, is there any way to move and change the name, for example like file1.ext, file2.ext,...

Thanks!

This is not foolproof but it's likely to work, and will prompt if the small likelihood occurs that a filename exists. You'll need a batch file to make it foolproof and to improve the naming strategy.

Remove the @echo if you are happy with the result.

cmd /v:on /c for /f "delims=" %a in ('dir /b /s /a-d') do @echo copy “%a” “C:\YourFolder\%~na-!random!!random!!random!%~xa” /-y

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