#1 2008-01-08 12:53

andthus
Member
Registered: 2008-01-08
Posts: 3

Insert instead of replace in UserInput rule

I often have a list of strings that I want to <insert> into the successive filenames at a specified position rather than completely replace the filenames by the user input lines.  It would be great if the <insert> rule allowed userinput from a text document. 

Maybe the best way to do this (from a user perspective) would be to have something like a meta tag :UserInput: that would refer to the Nth line of a text document when renaming the Nth file.  This would have the advantage of being useful in the <replace> rule as well. 

(originally I had suggestions for several issues, but I figured out that they could all be solved by inserting strings from text documents smile

- andthus

PS Thanks for the super helpful program!!!

Offline

#2 2008-01-08 14:27

andthus
Member
Registered: 2008-01-08
Posts: 3

Re: Insert instead of replace in UserInput rule

<excitement> By browsing the forums I figured out how to make a PascalScript for inserting lines of a text document at position N of the filenames big_smile big_smile big_smile

var
  I: Integer;
  UserInput: WideString;
begin
  I := I+1;
  UserInput := FileReadLine('E:\UserInput.txt', I);
  WideInsert(UserInput, FileName, N);
end.

Since the last line can be easily modified to insert in other ways, my issues are solved, and now it's up to your obviously excellent judgement to decide whether it's still worth including a feature to do this automatically smile

Many thanks,

- andthus

Offline

#3 2008-01-11 14:25

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

Re: Insert instead of replace in UserInput rule

Good man, you found it! smile

I had that idea in the past, about adding such options to the UserInput rule, i.e. insert instead of replace. But I stopped my self while thinking that it will be complete duplication of the Insert rule (all its options), which might dramatically over-complicate the UserInput rule. And as you have found your-self, there is not real need for that either, because these options can be simulated via the PascalScript rule.

I'm still thinking it would be good to add a simple choice "Replace the name" (default behaviour) OR "Insert into the name" (simply at the beginning), because once it is inserted, user can use other rules to move the inserted part around. What do you think?

By the way, if you are going to be processing large amount of files, the script below will work faster, because it will read the file only once and store all the lines internally for later usage.

const
  NAMES = 'E:\UserInput.txt';
var
  Initialized: Boolean;
  Lines: TStringsArray;
  I: Integer;
begin
  if not Initialized then
  begin
    Lines := WideSplitString(FileReadContent(NAMES), #13#10);
    Initialized := True;
  end;
  if I < Length(Lines) then
  begin
    WideInsert(Lines[i], FileName, 1);
    I := I + 1;
  end;
end.

Offline

#4 2008-01-11 14:30

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

Re: Insert instead of replace in UserInput rule

Here is another workaround...

After you used UserInput rule and you lost your original filename, you can easily recover it from the FilePath:

begin
  WideInsert(WideExtractBaseName(FilePath), FileName, 1);
end.

Offline

Board footer

Powered by FluxBB