Skip to content | Sauter la navigation | Reading comfort | Confort de lecture

DOS Shell script to rename multiple files in one line

I needed to prefix a long list of files with a number, so I looked around and did not find much info, so I thought it might be useful for someone if I post it here (yes, some of us are still using Windows).

Here is how to prefix files: for %i in (*.*) do (ren "%i" "prefix %i")

And here is how to prefix folders: for /D %i in (*.*) do (ren "%i" "prefix %i")

The whole For syntax is explained on Microsoft’s web site: For in batch files.

Comments: share your thoughts! RSS

  • DOS Shell script to rename multiple files in one line (13 December 2007, by Jimmy)

    that was useful, i needed to suffix something and this almost worked for %i in (*.*) do (ren "%i" "%i_suffix.abc") problem with this is that the file extension gets included in the name twice ie. abc.xls turns into abc.xls_suffix.abc

    Do you know a solution?

    Reply to this message

  • DOS Shell script to rename multiple files in one line (12 March 2008, in reply to Jimmy)

    Within Windows XP you need to use a double percentage mark to catch filesnames (in this case) into variables. Also you have to remove the brackets or the command after the DO statement will not work properly

    The DOS command should look something like this:

    for %%i in (*.*) do ren "%%i" "prefix_%%i"

    Reply to this message