Batch file rename with suffix as 01 02 03 04 and so on

Solution 1:

I believe you'll want to post this question in Stack Overflow if you want someone to help you write a script for your purposes. To follow the outline of this forum here, I will provide you with a link to a program called Bulk Rename Utility. It's been recommended in the past by other Stack Exchange users and seems to fit your criteria.

http://www.bulkrenameutility.co.uk/Main_Intro.php

Solution 2:

File rename with suffix as 01 02 03 04 etc

Throw away your unsuitable script. You don't need random numbers and it doesn't handle .png files.

I've written a new script from scratch as was easier than trying to fix your broken script.

Use the following batch file:

@echo off
setlocal enabledelayedexpansion
rem initialise counter
set /a "x=1"
rem process jpg and png files
for /f "usebackq tokens=*" %%i in (`dir /b *.jpg *.png`) do (
  rem split into name and extension
  set _name=%%~ni
  set _ext=%%~xi
  rem pad the counter to 2 digits
  set "y=0!x!"
  set "y=!y:~-2!"
  rem do the rename
  ren "%%i" "!_name!-!y!!_ext!"
  increment counter
  set /a "x+=1"
  )
endlocal

Limitations:

  • Only processes .jpg and .png in the current working directory.
  • Only processes up to 99 files.

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • dir - Display a list of files and subfolders.
  • enabledelayedexpansion - Delayed Expansion will cause variables to be expanded at execution time rather than at parse time.
  • for /f - Loop command against the results of another command.
  • parameters - A command line argument (or parameter) is any value passed into a batch script.
  • set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
  • variables - Extract part of a variable (substring).