#1 2020-06-15 07:05

dannician
Member
Registered: 2019-07-06
Posts: 31

Adding "1 of 3", "2 of 3", "3 of 3" etc... numbering to file name.

Is there a way to add a 1 of "number" to file names.

Folder
     File 1.jpg
     File 2.jpg
     File 3.jpg


Result Folder

     File 1 of 3.jpg
     File 2 of 3.jpg
     File 3 of 3.jpg

Offline

#2 2020-06-15 08:00

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

Re: Adding "1 of 3", "2 of 3", "3 of 3" etc... numbering to file name.

By using an PascalScript this would be possible

http://www.den4b.com/forum/viewtopic.php?pid=8669#p8669




 


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#3 2020-06-15 08:30

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

Re: Adding "1 of 3", "2 of 3", "3 of 3" etc... numbering to file name.

Something like this:

var
  SerialNumber: Integer;
  FilesCounter: TWideStringArray;
begin
    SetLength(FilesCounter, 0);
    WideScanDirForFiles(WideExtractFileDir(FilePath), FilesCounter, False, False, False, '*');

    SerialNumber := SerialNumber+1;

    FileName := WideExtractBaseName(FileName) 
                + 'File ' +  IntToStr(SerialNumber)  
                + ' of '  + IntToStr(Length(FilesCounter)) 
                + WideExtractFileExt(FileName);
end.

More info about PascalScript:
https://www.den4b.com/wiki/ReNamer:Rules:PascalScript
https://www.den4b.com/wiki/ReNamer:Pasc … Management


- - -

EDIT: script modified to reset file counter if folder name change

var
  SerialNumber: Integer;
  FilesCounter: TWideStringArray;
  CurrentFolder, LastFolder, SerialString: WideString;
  
begin
    //get number of files in current folder into var 'FilesCounter'
    SetLength(FilesCounter, 0);
   // WideScanDirForFiles(WorkDir, returnVar, Recursive, IncludeHidden, IncludeSystem, Mask);  
    WideScanDirForFiles(WideExtractFileDir(FilePath), FilesCounter, False, False, False, '*');

    //increase file counter by 1:
    SerialNumber := SerialNumber+1;
    
   //reset file counter to 1 if folder name change:
    CurrentFolder := WideExtractFileDir(FilePath);
    if not WideSameText(CurrentFolder, LastFolder) then SerialNumber := 1;

   //Pad SerialNumber to wanted length (change "<1" to "<3" to get SerialString with at least three digits):
   SerialString := IntToStr(SerialNumber);
   While (Length(SerialString) < 1) Do
          SerialString := '0'+ SerialString;

    //compose new filename:
    FileName := WideExtractBaseName(FileName)
                + ' - File ' +  SerialString
                + ' of '  + IntToStr(Length(FilesCounter))
                + WideExtractFileExt(FileName);   


    LastFolder := CurrentFolder;
end.




 

Last edited by Stefan (2020-06-15 16:57)


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#4 2020-06-15 15:57

dannician
Member
Registered: 2019-07-06
Posts: 31

Re: Adding "1 of 3", "2 of 3", "3 of 3" etc... numbering to file name.

The file counter script produces 0.

//get number of files in current folder into var 'FilesCounter'
    SetLength(FilesCounter, 0);
    WideScanDirForFiles(FilePath, FilesCounter, False, False, False, '*');

Offline

#5 2020-06-15 17:01

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

Re: Adding "1 of 3", "2 of 3", "3 of 3" etc... numbering to file name.

dannician wrote:

The file counter script produces 0.


Ah, yes sorry, now already adjusted above.


"WideScanDirForFiles(FilePath" changed to "WideScanDirForFiles(WideExtractFileDir(FilePath)"




 


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#6 2020-06-15 19:12

dannician
Member
Registered: 2019-07-06
Posts: 31

Re: Adding "1 of 3", "2 of 3", "3 of 3" etc... numbering to file name.

THANK YOU!  That is very close.  Now I see that there are more than just .jpg files in the folder that are being counted.  Is there a way to modify the script to only count .jpg files?

Found the solution in the Mask portion of the WideScanDirForFiles(WorkDir, returnVar, Recursive, IncludeHidden, IncludeSystem, Mask)

Last edited by dannician (2020-06-15 19:50)

Offline

Board footer

Powered by FluxBB