You are not logged in.
Hi,
Here is my final script
I have changed:
-Add the Old
-Changed FilePath with FileName (so the column is smaller because I have "folder as files")
-Add the section "Current>Previous"
var
NameData, Files: TStringsArray;
Total, Previous, Old, Current: 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');
Old := StrToInt(NameData[1]);
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;
If (Current>Previous) then
begin
NameData[1] := IntToStr(Old);
NameData[2] := IntToStr(Current);
FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end;
end.
Last edited by ozzii (2011-06-20 17:55)
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
Take a look at this, I think this should do the same, just a little bit tidier:
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;
NameData[2] := IntToStr(Current);
FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end.
Last edited by SafetyCar (2011-06-20 19:54)
If this software has helped you, consider getting your pro version. :)
Offline
Thanks, little smaller than mine
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
Offline
I have another question...
Any way in the script to tell that the NameData[1] is on 2 digits.
Because now he's renamed "02" with "3" for example...
Maybe something with "If (length(NameData[1])=1) then"
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
Maybe something with "If (length(NameData[1])=1) then"
Yeah, that might work
You can put, at the end, before "NameData[2] := IntToStr(Current);" this:
If (length(NameData[1])=1) then NameData[1] := '0' + NameData[1];
Just for info. The usual way is:
while (length(NameData[1])<2) then NameData[1] := '0' + NameData[1];
because it's more generic and let's you pad till the number of digits you want. (Your's is only valid for 2 digits)
If this software has helped you, consider getting your pro version. :)
Offline
Thanks, working (as usual)....
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
I reup this post for another question.
Sometimes in my folder name I have XXX-vu 01(01) and sometimes without the "-vu" : XXX 01(01)
What I would like it's to modify the script that the NameData[1] is incremented only when I have "-vu" in NameData[0].
And when I don't have the -vu that I have
FileName := NameData[0] + '-vu ' + NameData[1] + '(' + NameData[2] + ')';
And of course I have to add a NameData[1] := 0
Clear enough !?
A little help SafetyCar
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
To be honest I don't really know what you meant with NameData[1] := 0;
And I almost leave you without incrementing ND[2] either, but I corrected .
But let's see with this. (And I hope that I didn't forget past changes on the base script)
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');
Current := Length(Files);
SetLength(Files, 0);
if (WideTextPos('-vu ', NameData[0])>0) then
begin
Deleted := StrToInt(NameData[1]);
Previous := StrToInt(NameData[2]);
If (Current<Previous) then
begin
Total := Deleted + Previous;
NameData[1] := IntToStr(Total - Current);
end;
while (length(NameData[1])<2) do NameData[1] := '0' + NameData[1];
end
else
begin
NameData[0] := NameData[0] + '-vu ';
NameData[1] := '0';
end;
NameData[2] := IntToStr(Current);
FileName := NameData[0] + NameData[1] + '(' + NameData[2] + ')';
end.
Last edited by SafetyCar (2011-10-05 14:11)
If this software has helped you, consider getting your pro version. :)
Offline
Something wrong but I can't found what (but i've tried).
I have deleted the NameData[1] := 0 this was just for a declaration.
This is my folders (with no files inside):
FOLDER S00(2)
FOLDER S01-vu 00(2)
With the modified script I have:
FOLDER S-vu 0(0)
FOLDER S01-vu 02(0)
But in final I must have:
FOLDER S00-vu 02(0)
FOLDER S01-vu 02(0)
So I think that the NameData[0] need to have the S00, maybe something like
^(.*? S\d\d)
But when I put this I have an error in "WideTextPos".
Actually, because of my folders name I've change to
If (length(NameData)<2) then Exit;
I think that the easiest way it's to almost leave all like the old script but add/change in front in that order
-change the NameData[0] to include inside the S??
-test the "-vu " into the whole name
-if there is not -vu then just add : NameData[0] := NameData[0] + '-vu ';
-and after that the old script will work.
I'm not sure if I am clear!?
Last edited by ozzii (2011-10-05 15:27)
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline