Search code examples
windowsfilerenamemovecommand-prompt

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!


Solution

  • 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