Batch rename files within subfolders using command prompt in Windows

Written by ppolyzos

Software engineer based in Athens, Greece

4 Comments

  1. Jozef

    Thank you PPOLYZOS.
    Please, how would you rename files within subfolders by taking the subfolder name and put it as prefix to filename which is in that subfolder?
    For example:
    subfolder: “SubFolderName”, original files: “Image1.jpg, Image2.jpg”, output files: “SubFolderName_x.jpg” and “SubFolderName_yz.jpg”

    1. ppolyzos

      You could generate the commands to rename the files using the following script:

      @echo off
      for /r %%a in (*.jpg *.png) do for %%b in ("%%~dpa\.") do echo ren "%%~a" "%%~nxb%%~xa"
      pause

      * %%a: returns each filespec recursively
      * %%b: helps make the folder as filename
      * %%~nxb: returns the filename and extension of %%b
      * %%~xa: returns the .extension of the %%a

      Or use a tool like KRename or any alternative to it.

Leave a Comment

Your email address will not be published. Required fields are marked *