You are not logged in.
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
Last edited by ozzii (2011-06-18 11:06)
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
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
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....
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
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
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
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 )
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
Ups, I didn't noticed that part
This is easy to say.... you just didn't want to do it that all
(just kidding)
Now, I made some changes, but I haven't tested it (I hope it still works
)
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 Have a nice Sunday..
_________________
Do, or do not. There is no 'try.'" -- Jedi Master Yoda
Offline
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.
But I'll let you try by yourself.
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
I know nothing about pascal script
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
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
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
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.
Thanks again (I think I repeat things no!)
Happy to help.
If this software has helped you, consider getting your pro version. :)
Offline