#1 2021-11-18 23:18

AJS
Member
Registered: 2021-11-18
Posts: 2

Serialize improvement

Hello! Thank you so much for this tool and its development. I'm using it a lot!

I'm very happy with serialization new features (as 'reset if folder changes' and 'reset if file name changes') but I see many people asking for solving similar serialization needs. So, I' like to suggest an improvement: Is it possible to implement a nested (priorized) serialization (maybe at most 3 levels)? I guess that would help many of seen needs and mine as follows:

I need to rename the following data:

chocolate cupcake 2323.jpg -> 5672-01
chocolate cupcake 23a123-gs.jpg -> 5672-02
strawberry cupcake ks198-fg.jpg -> 5673-01
Nutella browning 321.jpg -> 5674-01
Nutella browning 921.jpg -> 5674-02

That is, increment only the first part (from a specific number) when the name changes and increment the second part (from another specific number) only while in the same name!

I've seen some similar approaches in this forum, but using part of the old name or metadata information from the file itself, but no example of a brand new name formed by a serial.

I've tried to compose many rules like:

#1 rearrange using 'space' as delimiters, skip extension, with new pattern as '$1 $2';

As result, names would be (name root for further serialize processing):

chocolate cupcake.jpg
chocolate cupcake.jpg
strawberry cupcake.jpg
Nutella browning.jpg
Nutella browning.jpg

#2 serialize resetting index when name changes, replacing current name;

As result:

1.jpg
2.jpg
1.jpg
1.jpg
2.jpg

In fact, that's the second part intended for the name! But I still need to serialize the first part just when name changes and starting from a specific number!

Please, someone can help me? Thank you!

Best regards!

Offline

#2 2021-11-19 04:40

AJS
Member
Registered: 2021-11-18
Posts: 2

Re: Serialize improvement

Hi again!

I hadn't touch Pascal for years, but I tried to understand Renamer logic and started to get rid of my Pascal-programming rust!

I developed the following code, which seems to work for me (perhaps needs further testing on more files):

var
  NewFileName, OldFileName, StrCounter1, StrCounter2: WideString;
  Counter1, Counter2: Integer;

const
  Base = 25;

begin
    if OldFileName = FileName then
        begin
            OldFileName := FileName;
            Counter2 := Counter2 + 1
        end
    else
        begin
            OldFileName := FileName;
            Counter1 := Counter1 + 1;
            Counter2 := 1;
        end;

    StrCounter1 := IntToStr(Counter1 + Base);

    while (Length(StrCounter1) < 4) do
        begin
            StrCounter1 := '0' + StrCounter1;
        end;

    StrCounter2 := IntToStr(Counter2);

    while (Length(StrCounter2) < 2) do
        begin
            StrCounter2 := '0' + StrCounter2;
        end;


    FileName := StrCounter1 + '-' + StrCounter2 +  WideExtractFileExt(FileName);

end.

I had this results using following rules:

#1 rearrange using 'space' as delimiters, skip extension, with new pattern as '$1 $2';
#2 Pascal script as listed above;

And got results:

0026-01.jpg
0026-02.jpg
0027-01.jpg
0028-01.jpg
0028-02.jpg

I took about 1'22" to validate almost 17,400 files.

I hope that helps someone and feel free to suggest and improve this script! Thank you!

Last edited by AJS (2021-11-19 04:43)

Offline

#3 2021-11-20 14:07

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,156

Re: Serialize improvement

That's great work!

Thank you for sharing. I am sure it will come handy for other users.

For those trying to get started with the Pascal Script:
https://www.den4b.com/wiki/ReNamer:Pascal_Script

Offline

Board footer

Powered by FluxBB