#1 2011-06-18 11:04

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Tricky rename for folder

Hi,
I use this right now for renaming the folder depending of files inside it (thank again for that rule):

var
  Files: TStringsArray;

begin
  SetLength(Files, 0);
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.mkv');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.avi');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.wmv');
    
  FileName := FileName + '(' + IntToStr(length(Files)) + ')';
end.

In result I have this: folder-saw 10(15)

Now what I would like:
-If the folder have "saw" in the title and there is less files than before
-the name will be the difference between before and now added to the "saw" name.

Here is the example:
-Now I have this "folder-saw 10(15)"
-I delete a file inside the folder
-the result will be "folder-saw 11(14)" (I had 15, I subtract one to 15, I add one it to the saw number)
- I delete again 2 files
-the result is "folder-saw 13(12)" (I had 14, I subtract 2 to 14, I add 2 to the saw number)

Am I clear enough !??

Sorry for the title but I can't find something better cool

Last edited by ozzii (2011-06-18 11:06)


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#2 2011-06-18 12:41

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Tricky rename for folder

Try with this

var
  NameData, Files: TStringsArray;
  Total: Integer;

begin
  NameData := SubMatchesRegEx(FilePath, '^(.*?)(\d+)\((\d+)\)$', False);
  If (length(NameData)<>3) then Exit;
  
  SetLength(Files, 0);
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.mkv');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.avi');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.wmv');
  
  Total := StrToInt(NameData[1]) + StrToInt(NameData[2]);
  NameData[1] := IntToStr(Total - length(Files));
  NameData[2] := IntToStr(length(Files));
  
  FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end.

If this software has helped you, consider getting your pro version. :)

Offline

#3 2011-06-19 09:51

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Tricky rename for folder

Thanks SafetyCar for the quick reply (as usual)...
This is working... almost as I want...
The only thing that it's not doing it's the rename only if there is less files than before.

I have try to add a compare between the old value inside the "()" and the new but without success....  mad
Can you also explain to me what is this doing:

If (length(NameData)<>3) then Exit;

Please a little more help we (of course you can read YOU here) have almost finished tongue


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#4 2011-06-19 10:23

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Tricky rename for folder

ozzii wrote:

The only thing that it's not doing it's the rename only if there is less files than before.

Ups, I didn't noticed that part

ozzii wrote:

Can you also explain to me what is this doing:

If (length(NameData)<>3) then Exit;

Yes, that part is basically because, after searching for the info on the name, if there are no matches, then it will give an error building the filename at the end. The rule above it is suposed to give 3 values, with that, if there are no matches it quits from executing the rest.


Now, I made some changes, but I haven't tested it (I hope it still works  tongue)

var
  NameData, Files: TStringsArray;
  Total, Previous, Current: Integer;

begin
  NameData := SubMatchesRegEx(FilePath, '^(.*?)(\d+)\((\d+)\)$', False);
  If (length(NameData)<>3) then Exit;
  
  SetLength(Files, 0);
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.mkv');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.avi');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.wmv');
  
  Previous := StrToInt(NameData[2]);
  Current := Length(Files);
  
  If (Current<Previous) then
  begin
    Total := StrToInt(NameData[1]) + Previous;
    NameData[1] := IntToStr(Total - Current);
    NameData[2] := IntToStr(Current);
 
    FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
  end;
end.

Last edited by SafetyCar (2011-06-19 10:28)


If this software has helped you, consider getting your pro version. :)

Offline

#5 2011-06-19 10:52

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Tricky rename for folder

SafetyCar wrote:

Ups, I didn't noticed that part

This is easy to say.... you just didn't want to do it that all lol tongue lol  (just kidding)

SafetyCar wrote:

Now, I made some changes, but I haven't tested it (I hope it still works  tongue)

Working thanks...
Now I will try to combine the 2 work into one (because I have the 2 script as example).

Thank you again for your great help cool  Have a nice Sunday..


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#6 2011-06-19 12:57

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Tricky rename for folder

ozzii wrote:

Now I will try to combine the 2 work into one (because I have the 2 script as example).

I thought about asking you about that, but I forgot about it.

Maybe won't be that hard for you since you previously asked me about the part of the code you have to change.  tongue
But I'll let you try by yourself. lol wink

I don't know how much you know about PascalScrip, but you might find something helpful here:
http://www.den4b.com/wiki/ReNamer:Pasca … uick_guide


If this software has helped you, consider getting your pro version. :)

Offline

#7 2011-06-19 13:17

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Tricky rename for folder

I know nothing about pascal script  big_smile
But just had to update this new one and add an ">" for comparison and all is done (at least I think so).
But even if didn't work, I can (like now) have the 2 script in on preset.

Thanks again for the help.


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#8 2011-06-19 13:40

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Tricky rename for folder

I thought you got it when you asked about that part of code above.

Doesn't mind, maybe is this what you wanted?

var
  NameData, Files: TStringsArray;
  Total, Previous, Current: Integer;

begin
  SetLength(Files, 0);
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.mkv');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.avi');
  WideScanDirForFiles(FilePath, Files, False, False, False, '*.wmv');
  
  NameData := SubMatchesRegEx(FilePath, '^(.*?)(\d+)\((\d+)\)$', False);
  
  If (length(NameData)=3) then
  begin  
    Previous := StrToInt(NameData[2]);
    Current := Length(Files);

    If (Current<Previous) then
    begin
      Total := StrToInt(NameData[1]) + Previous;
      NameData[1] := IntToStr(Total - Current);
      NameData[2] := IntToStr(Current);

      FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
    end;
  end
  else
  begin
    FileName := FileName + '(' + IntToStr(length(Files)) + ')';
  end;
end.

If this software has helped you, consider getting your pro version. :)

Offline

#9 2011-06-19 14:47

ozzii
Senior Member
Registered: 2007-07-04
Posts: 101

Re: Tricky rename for folder

I didn't explain myself well.
Instead of just a "Current<Previous" i will also add an "else" "Current>Previous" and add the old code.

Thanks again (I think I repeat things no!)


_________________
Do, or do not. There is no 'try.'" --  Jedi Master Yoda

Offline

#10 2011-06-19 20:02

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Tricky rename for folder

ozzii wrote:

I didn't explain myself well.
Instead of just a "Current<Previous" i will also add an "else" "Current>Previous" and add the old code.

Well I'm still a little bit confused, maybe later you want to post your code for us to review it. wink

ozzii wrote:

Thanks again (I think I repeat things no!)

Happy to help.  big_smile


If this software has helped you, consider getting your pro version. :)

Offline

Board footer

Powered by FluxBB