#1 2015-05-22 12:56

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Add Numbering - reset if a PART of file name changes

 
Add numbering to same PART OF name

Add serialization but reset if a special part of the file name changes, like here the day part:

Dimitri wrote:

Once I have this file names:

IMG_101_2015-05-15 <
IMG_102_2015-05-15
IMG_103_2015-05-17 <
IMG_104_2015-05-18 <
IMG_105_2015-05-19 <
IMG_106_2015-05-19
IMG_107_2015-05-19

I would like to rename at the end as follows:

IMG_101_2015-05-15_001 <-- #1 for day 15
IMG_102_2015-05-15_002
IMG_103_2015-05-17_001 <-- #1 for day 17
IMG_104_2015-05-18_001 <-- #1 for day 18
IMG_105_2015-05-19_001 <-- #1 for day 19
IMG_106_2015-05-19_002
IMG_107_2015-05-19_003

Apparently what I’m trying to do, is add an incremental number that restarts on each day.
Even if a day has a single image, the name must have a number.

Is there a way to do that?

Thanks in advance!!

 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#2 2015-05-22 13:02

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Add Numbering - reset if a PART of file name changes

FROM:
IMG_101_2015-05-15
IMG_102_2015-05-15
IMG_105_2015-05-19
IMG_106_2015-05-19

TO:
IMG_101_2015-05-15_001 <-- 1 for day 15
IMG_102_2015-05-15_002
IMG_105_2015-05-19_001 <-- 1 for day 19
IMG_106_2015-05-19_002


Try this den4b ReNamer PascalScript


(Read our wiki how to use an script >> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript )



Note: for name differ from your example names, you have to adjust the RegEx expression to extract the NamePart 1 and 2.

var
  oldName, NamePart1, NamePart2, strNumber, Storage: WideString;
  Number: Integer;
  
begin
   oldName := WideExtractFileName(FileName);
   //Match on "IMG_101_2015-05-15" > "IMG_101_" + "2015-05-15"
   NamePart1 := ReplaceRegEx(oldName, '(IMG_\d\d\d_)(.+)', '$1', False, True);
   NamePart2 := ReplaceRegEx(oldName, '(IMG_\d\d\d_)(.+)', '$2', False, True);
 
   If (NamePart2 = Storage) Then Number := Number+1 else Number := 1;

   strNumber := IntToStr(Number);
   If (Length(strNumber) <2) Then strNumber := '0'+ strNumber;

  FileName := NamePart1 + NamePart2 
              + '_' + strNumber 
              + WideExtractFileExt(FileName);

  Storage := NamePart2;
end.



 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB