#1 2006-07-31 13:25

Watson
Member
Registered: 2006-07-31
Posts: 2

Renaming files generated by PDF Ripper

Hi Denis!! First of all, thanks for this amazing program, the better I ever find for renaming files!!!

I want to use Renamer for serialize names of files generated by PDF Ripper, but I got a problem...

The files generated by PDF Ripper are in the following format:

nameofPDFfile -1_1
nameofPDFfile -2_1
nameofPDFfile -3_1
nameofPDFfile -4_1
nameofPDFfile -5_1

etc..

The problem is, while Windows Explorer sorts correctly by name, Renamer sorts this way:

nameofPDFfile -1_1
nameofPDFfile -10_1
nameofPDFfile -11_1
        .
        .
        .
nameofPDFfile -19_1
nameofPDFfile -2_1
nameofPDFfile -20_1
nameofPDFfile -21_1

etc..

If I rename this way, I will got the pages in wrong sequence...

I think this happens because PDF Ripper don?t use 01 instead 1, but the fact is, there is not configuration in PDF Ripper to change this..

I try in Renamer many rules, but don?t realize...

Can you help me with this problem?!?!

Thanks in advance!!

Watson

Offline

#2 2006-07-31 17:27

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renaming files generated by PDF Ripper

you could add this as a pascalscript rule

var
  BaseName, Extension: string;
  EndDigitsCount, I: Integer;
  NotDigit:boolean;
const
  PAD_TO_LENGTH = 3;

procedure Inc(var A: Integer);
begin
  A := A + 1;
end;

begin
  EndDigitsCount := 0;
  BaseName := WideToAnsi(WideExtractBaseName(FileName));
  Extension := WideToAnsi(WideExtractFileExt(FileName));

  I:=length(BaseName);
  while I>0 do
  begin
      EndDigitsCount := 0;

   NotDigit:=true
   while IsWideCharDigit(BaseName[i]) do
   begin
     EndDigitsCount:=EndDigitsCount+1;
     I:=I-1;
     NotDigit:=false;
   end;
   If NotDigit then
     I:=I-1;

     if (EndDigitsCount > 0) and (EndDigitsCount <= PAD_TO_LENGTH) then
    while EndDigitsCount < PAD_TO_LENGTH do
      begin
      Insert('0', BaseName, I+1);
      EndDigitsCount:=EndDigitsCount+1 ;
      end;
  end;

  FileName := AnsiToWide(BaseName + Extension);

end.

Change the line
PAD_TO_LENGTH = 3;
to however many digits you would like
eg  PAD_TO_LENGTH = 2;


nameofPDFfile -1_1
nameofPDFfile -10_1
nameofPDFfile -11_1
would be changed to
nameofPDFfile -01_01
nameofPDFfile -10_01
nameofPDFfile -11_01

Then you could resort and do any other renaming you like

Offline

#3 2006-07-31 18:20

Watson
Member
Registered: 2006-07-31
Posts: 2

Re: Renaming files generated by PDF Ripper

dloneranger, thank you very much!!!

If I understand, I will make 2 separated operations: first, I use your script, after that, I apply my rules to renaming files. Ok?!?

In my initial tests, everything runs fine...

Thanks again!!!

Offline

#4 2006-07-31 18:37

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renaming files generated by PDF Ripper

Glad to be of help smile

Offline

#5 2006-07-31 19:28

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

Re: Renaming files generated by PDF Ripper

Upps, I'm a bit late for giving the solution wink

Dloneranger, the code that you used as a template was written for non-unicode filenames (you remember WideToAnsi and WideToAnsi conversation?), because of the bug in PascalScript. They still didn't get back to me, but in the v4.10 I've introduced new functions that allow a workaround for that problem.

Now, if you are bored, you could convert it to unicode-friendly script big_smile

Offline

#6 2006-07-31 20:44

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renaming files generated by PDF Ripper

den4b wrote:

Upps, I'm a bit late for giving the solution wink

Dloneranger, the code that you used as a template was written for non-unicode filenames (you remember WideToAnsi and WideToAnsi conversation?), because of the bug in PascalScript. They still didn't get back to me, but in the v4.10 I've introduced new functions that allow a workaround for that problem.

Now, if you are bored, you could convert it to unicode-friendly script big_smile

yeah - I was out of the house fixing someone's pc and just slipped that in as a quickie ;-)

ps one slight problem with the help for pascalscript is that the help box is modal, so you can't have it open whilst typing into the pascalscript editor - quick fix is just to fire up two instances of renamer

Last edited by dloneranger (2006-07-31 21:02)

Offline

#7 2006-07-31 21:15

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renaming files generated by PDF Ripper

how about this

var
  BaseName, Extension: WideString;
  EndDigitsCount, I: Integer;
  NotDigit:boolean;
const
  PAD_TO_LENGTH = 3;

begin
  EndDigitsCount := 0;
  BaseName := WideExtractBaseName(FileName);
  Extension := WideExtractFileExt(FileName);

  I:=WideLength(BaseName);
  while I>0 do
  begin
      EndDigitsCount := 0;

   NotDigit:=true;
   while IsWideCharDigit(WideGetChar(BaseName,I)) do
   begin
     EndDigitsCount:=EndDigitsCount+1;
     I:=I-1;
     NotDigit:=false;
   end;
   If NotDigit then
     I:=I-1;

     if (EndDigitsCount > 0) and (EndDigitsCount <= PAD_TO_LENGTH) then
    while EndDigitsCount < PAD_TO_LENGTH do
      begin
      WideInsert('0', BaseName, I+1);
      EndDigitsCount:=EndDigitsCount+1 ;
      end;
  end;

  FileName := BaseName + Extension;

end.

It'll have to be tested on some real unicode stuff of course

Offline

#8 2006-07-31 23:48

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renaming files generated by PDF Ripper

Or if you want it as a function

function NormalizeNumberLength(Fname:widestring; NumberLength:integer):widestring;
var
  BaseName, Extension: WideString;
  EndDigitsCount, I: Integer;
  NotDigit:boolean;
begin
  EndDigitsCount := 0;
  BaseName := WideExtractBaseName(FName);
  Extension := WideExtractFileExt(FName);

  I:=WideLength(BaseName);
  while I>0 do
  begin
      EndDigitsCount := 0;

   NotDigit:=true;
   while IsWideCharDigit(WideGetChar(BaseName,I)) do
   begin
     EndDigitsCount:=EndDigitsCount+1;
     I:=I-1;
     NotDigit:=false;
   end;
   If NotDigit then
     I:=I-1;

     if (EndDigitsCount > 0) and (EndDigitsCount <= NumberLength) then
    while EndDigitsCount < NumberLength do
      begin
      WideInsert('0', BaseName, I+1);
      EndDigitsCount:=EndDigitsCount+1 ;
      end;
  end;

  result := BaseName + Extension;
end;

begin
 FileName:=NormalizeNumberLength(FileName,5); end.

Change the 5 in 'NormalizeNumberLength(FileName,5)' to however many digits you want


Still haven't tested it on real unicode filenames, but it's fine on uk/us ascii codes

Last edited by dloneranger (2006-07-31 23:50)

Offline

#9 2006-07-31 23:53

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renaming files generated by PDF Ripper

Just a thought, a forum for pascalscript functions would tidy up these functions posted all over the place

I do like to see other people work big_smile

Offline

#10 2006-08-01 15:52

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

Re: Renaming files generated by PDF Ripper

dloneranger wrote:

Just a thought, a forum for pascalscript functions would tidy up these functions posted all over the place

Yes, a good thought, but I can't create a subforum within the forum, I will have to create a separate category of forums for it.

By the way, if you go to 'Search', and type "begin AND end" - it will find all the topics with PascalScript in it, I think smile

Offline

Board footer

Powered by FluxBB