Batch script to rename a file list without removing the last 6 characters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mrblack
Posts: 2
Joined: 06 Aug 2017 06:09

Batch script to rename a file list without removing the last 6 characters

#1 Post by mrblack » 06 Aug 2017 06:19

Hi everyone.
Please look at this image.
Is it possible to do a batch script that renames these files just to part01.rar, part02.rar, part03.rar, etc.?
Could you please help me?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to rename a file list without removing the last 6 characters

#2 Post by aGerman » 06 Aug 2017 07:20

Save this script in the folder with your rar archives.

Code: Select all

@echo off &setlocal
for /f "delims=" %%i in ('dir /a-d /b *.rar ^| findstr /reic:"\.part[0-9][0-9]\.rar"') do (
  set "file=%%i"
  setlocal EnableDelayedExpansion
  ren "!file!" "!file:~-10!"
  endlocal
)

Make sure that files have never the same part number!

Steffen

mrblack
Posts: 2
Joined: 06 Aug 2017 06:09

Re: Batch script to rename a file list without removing the last 6 characters

#3 Post by mrblack » 06 Aug 2017 07:57

Hi Steffen, the script works like a charm, you are the best. Thank you very much for your help.

Post Reply