#1 2010-08-12 13:10

Sceptic
Member
Registered: 2010-08-12
Posts: 4

How to reset serialization index if filename changes

Hi!

I have about 500 files in one folder, and they that look like:
abc_01.jpg
abc_03.jpg
abc_05.jpg
jhj_01.jpg
jhj_04.jpg
jkh_02.jpg
jkh_03.jpg
jkh_05.jpg

I need to serialize them so that each portion of files with the same name is in order, starting from 01 each time, like:

abc_01.jpg
abc_02.jpg
abc_03.jpg
jhj_01.jpg
jhj_02.jpg
jkh_01.jpg
jkh_02.jpg
jkh_03.jpg

I tried to do this with Renamer, using the Delete rule (remove two last digits) and Serialize, but I found that serialization within one folder goes like:

abc_01.jpg
abc_02.jpg
abc_03.jpg
jhj_04.jpg
jhj_05.jpg
jkh_06.jpg
jkh_07.jpg
jkh_08.jpg

Please, help!

Offline

#2 2010-08-12 14:22

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

Re: How to reset serialization index if filename changes

Hi Sceptic, welcome!

I guess we had to write an PascalScript to achieve that big_smile

I am sure somebody will help you, if not i take a lot this evening.

Please provide real file name examples, or, at least, is the delimiter always the underscore?
Could there be more than one underscore in an file name?


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

#3 2010-08-12 14:38

Sceptic
Member
Registered: 2010-08-12
Posts: 4

Re: How to reset serialization index if filename changes

Hi, Stefan! Thanks for the reply.

Yes, delimiter is always the underscore, but underscore is used all the time to separate filename parts, like "big_white_apple_01"
So: files are divided into groups, two, three or four files in each group. All the files in all the groups have the same name except last two digits, and I want them serialized in order. It looks like:
786_red_socks_01.jpg
786_red_socks_04.jpg
786_red_socks_05.jpg
898323_onion_is_great_01.jpg
898323_onion_is_great_03.jpg

And the goal is:
786_red_socks_01.jpg
786_red_socks_02.jpg
786_red_socks_03.jpg
898323_onion_is_great_01.jpg
898323_onion_is_great_02.jpg

And so on. Thank you once again for your concern.

Offline

#4 2010-08-12 18:38

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

Re: How to reset serialization index if filename changes

Every the last underscore, OK.

Here is what i had in mind.

Please test this with all possible care! .... Rename only copies of your real files! ... I don't know how this works with many files.


FROM:
786_red_socks_01.jpg-
786_red_socks_04.jpg
786_red_socks_05.jpg
783_red_socks_12.jpg-
783_red_socks_14.jpg
783_red_socks_25.jpg
784_red_socks_21.jpg-
784_red_socks_34.jpg
785_red_socks_35.jpg-
785_red_socks_56.jpg
785_red_socks_64.jpg
785_red_socks_75.jpg
898323_onion_is_great_01.jpg-
898323_onion_is_great_03.jpg
898323_onion_is_great_12.txt
898323_onion_is_great_72.log
898333_onion_is_great_1.jpg-
TO:
786_red_socks_01.jpg-
786_red_socks_02.jpg
786_red_socks_03.jpg
783_red_socks_01.jpg-
783_red_socks_02.jpg
783_red_socks_03.jpg
784_red_socks_01.jpg-
784_red_socks_02.jpg
785_red_socks_01.jpg-
785_red_socks_02.jpg
785_red_socks_03.jpg
785_red_socks_04.jpg
898323_onion_is_great_01.jpg-
898323_onion_is_great_02.jpg
898323_onion_is_great_03.txt
898323_onion_is_great_04.log
898333_onion_is_great_01.jpg-


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

var
  Part1, LastPart1, Part2, StoreLast: WideString;
  Number: Integer;
  
begin
   LastPart1 := StoreLast;
   Part1 := ReplaceRegEx(WideExtractFileName(FileName), '(.+_).+', '$1', False, True);
   StoreLast := Part1;

   If (Part1 = LastPart1) Then Number := Number+1
    else Number := 1;

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

  FileName := Part1 + Part2 + WideExtractFileExt(FileName);
end.

HTH? big_smile

Last edited by Stefan (2010-08-12 18:53)


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

#5 2010-08-12 19:13

Sceptic
Member
Registered: 2010-08-12
Posts: 4

Re: How to reset serialization index if filename changes

Good evening, Stefan!
Thank you for replying once again, I've read your script and as far as I understand Pascal (not well, but enough for a female whose job is not related with programming), it does exactly what it should do, comparing the name (without extension and last digits) of the file with the next and either adding 1 to the current number, or resetting to 1 if the name differs. It looks awesome, and I can't wait to try it when I get to the office and my computer there.

I'll post tomorrow to tell if it worked or not. But I think it will!

Offline

#6 2010-08-13 08:59

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

Re: How to reset serialization index if filename changes

Sceptic wrote:

I'll post tomorrow to tell if it worked

and provide a few info too please: how many files, how long did it take?


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

#7 2010-08-13 09:11

Sceptic
Member
Registered: 2010-08-12
Posts: 4

Re: How to reset serialization index if filename changes

Stefan, it worked!

Unfortunately, I cannot tell you how long it took to rename all the 450 files, because I wasn't anywhere near my computer: as I started the the process, I went away and returned much later, half an hour or so, and it was all done by that time. But I think there is a possibility that the problem will occur once more, so next time I try this script I will write down the time it will take to rename all the files.

Thank you oh so very much!

Offline

#8 2017-05-27 08:32

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

Re: How to reset serialization index if filename changes

Option "Reset if file name changes" has been added to the Serialize rule in ReNamer v6.7.0.1 Beta.

Offline

#9 2017-05-30 11:20

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

Re: How to reset serialization index if filename changes

Works (of course) for me, thanks.



 


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