#1 2006-09-20 17:05

adirving
Member
Registered: 2006-09-20
Posts: 3

Delete Duplicate words in file name.

I have a file named: 1234 adirving adirving IV 09-20-2006
I want it to be remaned to: 1234 adirving IV 09-20-2006.
Is there a way to do this?

Offline

#2 2006-09-20 18:24

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

Re: Delete Duplicate words in file name.

Use the code below in PascalScript. It will remove all the duplicated words, so the last thing for you to do will be to remove the extra spaces, using CleanUp rule - fix spaces option.

var
  Words: TStringsArray;
  BaseName, Extension: WideString;
  I, A: Integer;

begin
  Extension := WideExtractFileExt(FileName);
  BaseName := WideExtractBaseName(FileName);
  Words := WideSplitString(BaseName, ' ');
  if WideArrayLength(Words) < 1 then Exit;
  
  for I:=0 to WideArrayLength(Words)-2 do
    for A:=I+1 to WideArrayLength(Words)-1 do
      if WideSameText(Words[i], Words[A]) then
        Words[A] := '';

  BaseName := Words[0];
  for I:=1 to WideArrayLength(Words)-1 do
    BaseName := BaseName + ' ' + Words[i];
  FileName := BaseName + Extension;
end.

Offline

#3 2013-04-18 19:32

tom.amitai
Member
Registered: 2013-04-18
Posts: 5

Re: Delete Duplicate words in file name.

I tried this script in version 5.70 of Renamer, and get the following error:

Preview process has been terminated due to a critical error:
Pascal Script Compile:
[Line 10] Error: Unknown identifier 'WideArrayLength'

Offline

#4 2013-04-18 19:52

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

Re: Delete Duplicate words in file name.

Hi tom, welcome.

Sorry for the inconvenience.

See History.txt:

ReNamer 4.50
• Updated PascalScript source :
     1) SetLength() and Length() functions work for both WideStrings and Arrays;
     2) Widestring indexed character access is working, i.e. WideString[1];
     Note: WideArrayLength() and WideArraySetLength() functions are removed!


So update the script to this by removing the 'WideArray' part:

var
  Words: TStringsArray;
  BaseName, Extension: WideString;
  I, A: Integer;

begin
  Extension := WideExtractFileExt(FileName);
  BaseName := WideExtractBaseName(FileName);
  Words := WideSplitString(BaseName, ' ');
  if Length(Words) < 1 then Exit;
  
  for I:=0 to Length(Words)-2 do
    for A:=I+1 to Length(Words)-1 do
      if WideSameText(Words[i], Words[A]) then
        Words[A] := '';

  BaseName := Words[0];
  for I:=1 to Length(Words)-1 do
    BaseName := BaseName + ' ' + Words[i];
  FileName := BaseName + Extension;
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