Search code examples
numbersfilenamesspaces

How do I rename a list of files whose names contain spaces and a sequentially changing number?


Say that I have a folder containing a list of Windows filenames that have spaces and numbers , where the number is different for each filename in the list. How can I use the Command Prompt window's RENAME command (or other commands) to rename the list of files ?

Example: I want to change a list of file names,

From:

My Photo 1.jpeg

My Photo 2.jpeg

.

.

.

My Photo 50.jpeg

To:

Your Photo 1.jpeg

Your Photo 2.jpeg

.

.

.

Your Photo 50.jpeg

Thank you.


Solution

  • You will need to do it in two DOS commands:

    dir /b My*.jpeg >x.txt
    for /f "tokens=1,2,3" %i in (x.txt) do ren "%i %j %k" "Your %j %k"
    

    ren My* Your* WILL NOT WORK PROPERLY
    you will end up with

    Yourhoto1.jpeg
    Yourhoto2.jpeg
    etc...