#11 2007-05-12 17:09

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

Re: rename the same filename but different extension

You remember the script that I sent you?

Try changing the line:
while Exists(Path + NewName) do
   into
while Exists(Path + NewName) or WideFileExists(Path + NewName + Ext) do

This should force the code to add counter if the destination file already exists.

Didn't try it my self, so tell me how it goes, ok?

Offline

#12 2007-05-12 18:40

bobyang
Member
Registered: 2007-05-08
Posts: 33

Re: rename the same filename but different extension

den4b wrote:

Didn't try it my self, so tell me how it goes, ok?

thank you but it doesn't work.
it adds "(2)" in the back even no the same filename (ignore extension) in that folder. I also delete the folder and it still changes to (2) by itself.
thank you!

Last edited by bobyang (2007-05-12 18:43)

Offline

#13 2007-05-13 23:41

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

Re: rename the same filename but different extension

I looked at the list of rules from your previous examples, and I think this might happen because your script rule is not the last in a sequence. At the moment where the script is executed, the new name might not change yet, causing the file to clash with itself on pascalscript rule, thus, adding the (2), (3), etc. Anyway, try placing the script as the last rule...

Offline

#14 2007-05-15 01:07

bobyang
Member
Registered: 2007-05-08
Posts: 33

Re: rename the same filename but different extension

den4b wrote:

I looked at the list of rules from your previous examples, and I think this might happen because your script rule is not the last in a sequence. At the moment where the script is executed, the new name might not change yet, causing the file to clash with itself on pascalscript rule, thus, adding the (2), (3), etc. Anyway, try placing the script as the last rule...

thank you! but it doens't work. I move it to the last statement and I still got the same thing.
However, I cannot really use it as the last statement because I have to run these before it: 1.don't do anything for & files and 2. move to the correct folder
File?id=dd5djd97_35cdn8shf8

thank you!!

Offline

#15 2007-05-15 13:15

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

Re: rename the same filename but different extension

96 rules... never seen anybody to use that many big_smile

Anyway, what happens - is exactly what I said. Before running last 2 rule, your new names are:
user1-test.txt
user1-test2.txt2

The script works with these names, and that is why they get serialized (their respective paths are already taken by then-selves).

Put the script as 96'th rule - as the last rule, and it should work. Run everything BEFORE that script.

Offline

#16 2007-05-15 20:30

bobyang
Member
Registered: 2007-05-08
Posts: 33

Re: rename the same filename but different extension

den4b wrote:

96 rules... never seen anybody to use that many big_smile

Anyway, what happens - is exactly what I said. Before running last 2 rule, your new names are:
user1-test.txt
user1-test2.txt2

The script works with these names, and that is why they get serialized (their respective paths are already taken by then-selves).

Put the script as 96'th rule - as the last rule, and it should work. Run everything BEFORE that script.

thank you! I know the problem now.. because I after eidting the script I click on "close" instead of "add" which will not save it tongue. and I capture the wrong screen in the last messeage.

However, it doens't fix the problem. i moved the script to the rule 96 and I get the same result.
Moreover, if I move it to the last statement, I cannot put them into different folders (rule 94 doens't take action)
thank you!
File?id=dd5djd97_36c8wr9hc8

Offline

#17 2007-05-15 20:58

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

Re: rename the same filename but different extension

I think you need to send me over your preset file, with all the rules...

Offline

#18 2007-05-16 03:39

bobyang
Member
Registered: 2007-05-08
Posts: 33

Re: rename the same filename but different extension

den4b wrote:

I think you need to send me over your preset file, with all the rules...

thank you! I have updated to here
http://www.sendspace.com/file/94nwou

Offline

#19 2007-05-16 12:47

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

Re: rename the same filename but different extension

Found a problem, and fixed it. Use the code below as your LAST (96-th) rule.

I replaced the WideExtractBaseName() with WideStripExtension(), because the first one actually removed the previously added folder name (by one of your rules). This new function is only available in the latest development version, which you can get from here: ReNamerBeta.zip

I tried it with sample files that you sent me, and it worked perfectly! smile

P.S. To optimize and shorten your 96 rules, you should change the Replace rules (which simply remove things) to Remove rule, and you could also group them together into one rule, because both Replace and Remove rule have multi-part delimiter which lets you do several operations in one rule.

var
  Files: TStringsArray;

procedure Add(const S: WideString);
begin
  SetLength(Files, Length(Files)+1);
  Files[Length(Files)-1] := S;
end;

function Exists(const S: WideString): Boolean;
var I: Integer;
begin
  Result := False;
  for I:=0 to Length(Files)-1 do
    if WideSameText(Files[i], S) then
      begin Result := True; Break; end;
end;

var
  NewName, Path, Name, Ext: WideString;
  Counter: Integer;

begin
  Counter := 2;
  Ext := WideExtractFileExt(FileName);
  Name := WideStripExtension(FileName);
  Path := WideExtractFilePath(FilePath);  
  NewName := Name;
  while Exists(Path + NewName) or WideFileExists(Path + NewName + Ext) do
  begin
    NewName := Name +'(' + IntToStr(Counter)+')'; 
    Counter := Counter + 1;
  end;
  Add(Path + NewName);
  FileName := NewName + Ext;
end.

Offline

#20 2007-05-16 20:19

bobyang
Member
Registered: 2007-05-08
Posts: 33

Re: rename the same filename but different extension

den4b wrote:

Found a problem, and fixed it. Use the code below as your LAST (96-th) rule.

I replaced the WideExtractBaseName() with WideStripExtension(), because the first one actually removed the previously added folder name (by one of your rules). This new function is only available in the latest development version, which you can get from here: ReNamerBeta.zip

I tried it with sample files that you sent me, and it worked perfectly! smile

P.S. To optimize and shorten your 96 rules, you should change the Replace rules (which simply remove things) to Remove rule, and you could also group them together into one rule, because both Replace and Remove rule have multi-part delimiter which lets you do several operations in one rule.

thank you!
and you can group them? nice! that's waht i want to do before about grouping!

yes, I should use remove instead of replace. the only reason I used it because I was thinking to setup one rule for all people to use and they may have special request of they watn to changing instead of removing. However, I only see two people asking me how to replace so I guess I can change it to remove instead to speed up.

Offline

Board footer

Powered by FluxBB