#1 2010-05-20 22:50

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

INSERT rule - Insert output of script

Idea:

an user create an script to do something like create an custom counter.

Then he have to use an regex subpattern part too to split the file name and
add the counter at the right place.



My assuming was just to use the insert rule to add the script result at the right place:

Insert Script Result: [path\script.pas][...]
Where Pos: 6
or
Where After Text: (


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 2010-06-03 15:15

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

Re: INSERT rule - Insert output of script

I see that it can be useful in practice, but it is not worth the development time.

Offline

#3 2010-06-03 20:39

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

Re: INSERT rule - Insert output of script

Thanks for considering this.

Since i found "WideInsert()" again today,
i build an framework to rebuild the Insert rule
as an addition to my main script
to insert the script result (e.g. an custom counter) in the FileName where i want at easy.

Note: i just build the script without many test runs, so test this with test files only.

You can use this whole script as addition for your script
or copy&paste just the procedure or just the code you need.

You can use more then one insert option at once if you like,
e.g.
  Prefix(InsertStr); 
AND
  Suffix(InsertStr);
AND
  Position(InsertStr, 3);

Hope this is helpful and i did not that many nonsense  big_smile

//InsertRule
////////////////////////////////////////////////////////////////////////////////////
///////// some procedures, don't modify  (Note: all skips extension) ///////////////

Procedure Prefix(InsertStr: WideString);
begin
   FileName := InsertStr + FileName;
end;

Procedure Suffix(InsertStr: WideString);
begin
   FileName := WideExtractBaseName(FileName) + InsertStr + WideExtractFileExt(FileName);
end;
 
Procedure Position(InsertStr: WideString; InsertPos: Integer);
var
 Base: WideString;
begin
   Base := WideExtractBaseName(FileName);
   WideInsert( InsertStr, Base, InsertPos);
   FileName := Base + WideExtractFileExt(FileName);
end;

Procedure PositionRight(InsertStr: WideString; InsertPos: Integer);
begin
   WideInsert( InsertStr , FileName, Length(WideExtractBaseName(FileName)) -InsertPos+2);
end;

Procedure AfterText(InsertStr, InsertAfterChar: WideString);
var
  InsertPos: Integer;
begin
   // Find the InsertPos automatically by searching 
   // the first occurrence of char 'x'
   IF (InsertAfterChar <> '') then
      InsertPos := pos(InsertAfterChar, FileName) +1;
   IF (InsertPos>1) Then 
      WideInsert( InsertStr , FileName, InsertPos);
end;

Procedure BeforeText(InsertStr, InsertBeforeChar: WideString);
var
  InsertPos: Integer;
begin
   // Find the InsertPos automatically by searching 
   // the first occurrence of char 'x'
   IF (InsertBeforeChar <> '') then
      InsertPos := pos(InsertBeforeChar, FileName);
   IF (InsertPos>1) Then 
   WideInsert( InsertStr , FileName, InsertPos);
end;
////////// end procedures //////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

//////// the main script here //////////////////////////////////////////////////////
var
 InsertStr: WideString;

begin
   
   //
   // Put your main script here...
   //
   // "InsertStr" is result from your "main script"
   InsertStr := '_TEST_';

  //New FileName (uncomment one or more as you need):
  
  //Prefix(InsertStr);  
  //Suffix(InsertStr);
  //Position(InsertStr, 3); 
  //PositionRight(InsertStr, 4); 
  //AfterText(InsertStr, '- ');    
  //BeforeText(InsertStr, ' -');     


  //or use an independent string: 'My string'
  Prefix('TEST_');  
  PositionRight(InsertStr, 4);   
  //Prefix('My string ');  
  //AfterText(' (', '- ');   
  //Suffix(')');
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