5

I have n number of files I want to rename by adding a common name in-between the existing name.

E.g.

"LRHP 100055"
"LRHP 200452"
"HRVG 500002_thumb"

I want to rename the above files to:

"LRHP 00100055"
"LRHP 00200452"
"HRVG 00500002_thumb"

In front of the number I want to add two zeros. My existing name should not change.

| improve this question | | | | |
2

Batch Script Rename and Add Double Zeros to a Part of a File Name

In the below examples I used a FOR /F loop to set delimiters and tokens parsing file name parts and use those to set variables for later use with the REN command. I've also utilized the Setlocal EnableDelayedExpansion to handle the expanding of the variables set in the loop accordingly to be properly used (not parsed at runtime) with the rename command per iteration within the loop.

Without a file Extension on the files to rename

@ECHO ON

SETLOCAL ENABLEDELAYEDEXPANSION
SET SourceDir=C:\Users\User\Desktop\Tester

FOR /F "TOKENS=1-2 DELIMS= " %%F IN ('DIR /B /A-D "%SourceDir%\*"') DO (
    SET "part1=%%~F" 
    SET "part2=%%~G" 
    SET "part3=%%~H"
    REN "%SourceDir%\!part1! !part2!" "!part1! 00!part2!"
)
GOTO EOF

enter image description here

With a file extension on the files to rename

@ECHO ON

SETLOCAL ENABLEDELAYEDEXPANSION
SET SourceDir=C:\Users\User\Desktop\Tester

FOR /F "TOKENS=1-3 DELIMS=. " %%F IN ('DIR /B /A-D "%SourceDir%\*"') DO (
    SET "part1=%%~F" 
    SET "part2=%%~G" 
    SET "part3=%%~H"
    REN "%SourceDir%\!part1! !part2!.!part3!" "!part1! 00!part2!.!part3!"
)
GOTO EOF

enter image description here


Further Resources

| improve this answer | | | | |
0

RenameFiles is my go-to Windows application for bulk file renaming.

  • Unfortunately, the original site is no longer available, so I have linked to my own copy.
  • Archive of original site for reference
  • For your task, check the option "Insert string" 00 after character 5:

enter image description here

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.