#21 2011-10-05 15:46

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

Re: Tricky rename for folder

But... with the old script...

FOLDER S00(2)

would be:

FOLDER S 00(2)

isn't it?


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

Offline

#22 2011-10-05 15:50

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

Re: Tricky rename for folder

No, with the old script the 00 is incremented, so I have (without file inside):
FOLDER S02(0)

Here is the script I'm using.

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

begin
  NameData := SubMatchesRegEx(FileName, '^(.*?)(\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');
  
  Current  := Length(Files);
  Deleted  := StrToInt(NameData[1]);
  Previous := StrToInt(NameData[2]);
  
  If (Current<Previous) then
  begin
    Total := Deleted + Previous;
    NameData[1] := IntToStr(Total - Current);
  end;
  
  If (length(NameData[1])=1) then NameData[1] := '0' + NameData[1];
  NameData[2] := IntToStr(Current);

  FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end.

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

Offline

#23 2011-10-05 16:09

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

Re: Tricky rename for folder

Sorry, I'm a mess right now.

I'm still wondering about "increment only when I have "-vu"", I'm not seeing it in the examples you gave after.

Anyway, take a look at this one:

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

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

    FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end.

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

Offline

#24 2011-10-05 16:19

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

Re: Tricky rename for folder

Sorry... I didn't sleep very well today lol

Maybe this one...  roll

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

begin
    NameData := SubMatchesRegEx(FileName, '^(.*?)(\d+)\((\d+)\)$', False);
    If (length(NameData)<>3) then Exit;
    
    WideScanDirForFiles(FilePath, Files, False, False, False, '*.mkv');
    WideScanDirForFiles(FilePath, Files, False, False, False, '*.avi');
    WideScanDirForFiles(FilePath, Files, False, False, False, '*.wmv');
    SetLength(Files, 0);
    
    Current    := Length(Files);

    if (WideTextPos('-vu ', NameData[0])=0) then
    begin
        NameData[0] := NameData[0] + NameData[1] + '-vu ';
        NameData[1] := '00';
    end
    else
    begin    
        Deleted    := StrToInt(NameData[1]);
        Previous := StrToInt(NameData[2]);
        
        If (Current<Previous) then
        begin
            Total := Deleted + Previous;
            NameData[1] := IntToStr(Total - Current);
        end;
        
        If (length(NameData[1])=1) then NameData[1] := '0' + NameData[1];
    end;
    
    NameData[2] := IntToStr(Current);

    FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end.

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

Offline

#25 2011-10-05 16:25

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

Re: Tricky rename for folder

This is it.
Even better than my idea because you've done it in one test..

But it's my mistake, I thought that the regex will always give
NameData := SubMatchesRegEx(FileName, '^(.*?)(\d+)\((\d+)\)$', False);
NameData[0] -> FOLDER S

This is why I am a little lost and I can't "understand" the WideTextPos with NameData[0]
Can you explain the first regex and the result, please!?


But, anyway, thanks for the help and the upgrade....


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

Offline

#26 2011-10-05 16:27

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

Re: Tricky rename for folder

You post when I was writing...
But the first work as well...


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

Offline

#27 2011-10-05 16:32

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

Re: Tricky rename for folder

The first is working and not the second:
with first
ACA S01(2)                ACA S01-vu 02(0)
ACA S02-vu 01(2)    ACA S02-vu 03(0)
ACA S03-vu 05(1)    ACA S03-vu 05(2)
aca S04(0)                   aca S04-vu 00(0)

with second
ACA S01(2)                ACA S01-vu 00(0)
ACA S02-vu 01(2)       ACA S02-vu 03(0)
ACA S03-vu 05(1)       ACA S03-vu 06(0)
aca S04(0)                aca S04-vu 00(0)

Last edited by ozzii (2011-10-05 16:33)


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

Offline

#28 2011-10-05 16:47

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

Re: Tricky rename for folder

ozzii wrote:

The first is working and not the second

Well... take the first then tongue

ozzii wrote:

I thought that the regex will always give
NameData := SubMatchesRegEx(FileName, '^(.*?)(\d+)\((\d+)\)$', False);
NameData[0] -> FOLDER S

This is why I am a little lost and I can't "understand" the WideTextPos with NameData[0]
Can you explain the first regex and the result, please!?

In fact, it does.

The RegEx searches for
^        >   From the start
(.*?)   >   NameData[0] = Anything until...
(\d+)  >   NameData[1] = Digits
\(       >   Open parenthesis
(\d+)  >   NameData[2] = More digits
\)       >   Close parenthesis
$        >   End of text

The problem was that we caught the first digits without having to take them, so I brought them back to where they should be with NameData[0] := NameData[0] + NameData[1];

ozzii wrote:

But, anyway, thanks for the help and the upgrade....

Happy to help.


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

Offline

Board footer

Powered by FluxBB