You are not logged in.
Hello,
let me first say thanks for this wonderful program. It is really one of the best, if not THE best renaming Tool ever
Thanks Denis.
Now to my questions. I'm trying to serialize duplicates as a sequence - for example:
test.doc > test -1.doc
test.doc > test -2.doc
test.doc > test -3.doc
exp.exp > exp -1.doc
exp.exp > exp -2.doc
I have found the serialize duplicates pascal script, and for what i'm trying to archive it is almost perfect. It just doesn't start to serialize at the first file.
test.doc > test.doc
test.doc > test (1).doc
test.doc > test (2).doc
Could the serialize duplicates script be modified so it includes the first duplicate into the serialize?
I just encountered the power of RegEx, but Pascal Scripting is still totally new to me.
Thanks a lot
FranCi
Offline
I have added a variant of the script to do it the way you have described: Wiki: Serialize duplicates.
Note that every file that doesn't contain duplicates will still have the "-1" appended because the list of files is parsed from top to bottom and there is no way script can know whether file will have duplicates at all.
Offline
Hi Denis,
thats why i try to use an second script after that original serialize script
to check if an file with current name and additional "(2)" exists
and then rename this first file by adding an "(1)",... but i don't get it to work:
EDIT: i modify the code and this should work as additional script after the first serializing,
but only as second run and after the files are sorted upside down, like
file (3).txt
file (2).txt
file.txt
by an click on the header of the Name column.
As always, try this with test files first.
//if an file "<current name>" plus addition " (2)" exists, rename current name by adding an " (1)".
//Note: you have to sort the "Name" column up-side down, Z to A, first.
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
NewFileName, dup: WideString;
begin
// the content of the var 'dup' has to be adjusted to match the real file name pattern:
//here we build the dup name by extracting the part of the current name till ' (2)'
dup := ReplaceRegEx(WideExtractBaseName(FileName), '(.+)\s\(2\)','$1',False, True);
//showmessage('#'+dup+'#');
dup := dup + '(2)' + WideExtractFileExt(FileName);
//now search if an dup name exists like the current name + ' ( 2)' + ext:
if Exists(dup) then
begin
//showmessage(dup);
//if such an name exists, rename current name by adding an ' (1)':
NewFileName :=
WideExtractBaseName(FileName) + ' (1)' + WideExtractFileExt(FileName);
end;
FileName := NewFileName;
Add(FileName);
end.
Last edited by Stefan (2010-05-23 08:59)
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Is there any way to assign variables on a pascal rule and read it from other pascal rule???
If this software has helped you, consider getting your pro version. :)
Offline
Thats interesting. So it seems this is not as easy to implement as i thought.
Stefan's idea sounds not bad, if it could get to work.
Thanks you guys for taking your time with this and looking into it.
Offline
Is there any way to assign variables on a pascal rule and read it from other pascal rule???
The reply is here.
I was asking this thinking on first pascal rule that makes an array of file names (or better if they are file paths). And other array related to the first one, counting the number of times that the name appears.
For example:
test.doc
test.doc
test.doc
exp.exp
We get the arrays with;
- test.doc, exp.exp
- 3, 1
So when the data is collected now with a second pascal rule, we can say
if the filename is in the list and has more than 1 occurrences then add the serialization
Just an idea...
Last edited by SafetyCar (2010-05-23 01:07)
If this software has helped you, consider getting your pro version. :)
Offline
I think you can't do that with one script only,
because at first there is no other duplicate file name...
only an second same name would be an duplicate.
So i imagine you have to run an first script (or other rules)
which finds one-or-more duplicates...
and only then you can see that there is an first occurrence too...
which you can rename in an second run (as my script above does (for me)).
But changes are i am not that good in logically work and someone come up with an better solution.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
My approach is wrong
I don't know why I was thinking that each rule was applied to each name before continuing with the next rule
If this software has helped you, consider getting your pro version. :)
Offline
You can still do this but in 2 runs.
First run: Store in a temporary file a list of names which have duplicates.
Second run: If new name is in the list of duplicates (loaded from temp file) then serialize.
Do you need a hand with it?
Offline
I did this, with some code from me an some from den4b script:
var
NamesDB: TStringsArray;
NamesTXT: WideString;
I, Count: Integer;
Initialized, EmptyVars: Boolean;
Files: TStringsArray;
NewFileName: WideString;
Counter: Integer;
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;
begin
NamesTXT := WideGetCurrentDir + '\~temp_vars_names.txt';
FileName := ReplaceRegEx(WideExtractBaseName(FileName), ' *(\(\d+\)|-\d+)$', '', False, False) + WideExtractFileExt(FileName);
If not Initialized then
begin
If not WideFileExists(NamesTXT) then FileWriteContent(NamesTXT, '');
If FileReadContent(NamesTXT)='' then EmptyVars:=True else EmptyVars:=False;
end;
If EmptyVars then
begin
FileAppendContent(NamesTXT, FileName + #13#10);
FileName := ':: Please do the Preview again ::';
end
else
begin
If not Initialized then
begin
NamesDB := WideSplitString(FileReadContent(NamesTXT), #13#10);
WideDeleteFile(NamesTXT);
end;
Count:=0
For I:=0 to length(NamesDB)-1 do
begin
If WideSameText(FileName, NamesDB[i]) then Count := Count + 1;
end;
If Count>1 then
begin
Counter := 1;
NewFileName := FileName;
If not Exists(FileName) then Add(FileName);
while Exists(NewFileName) do
begin
NewFileName :=
WideExtractBaseName(FileName) +
' -' + IntToStr(Counter)+'' +
WideExtractFileExt(FileName);
Counter := Counter + 1;
end;
FileName := NewFileName;
Add(FileName);
end;
end;
Initialized := True;
end.
My part of the code was this.
var
NamesDB: TStringsArray;
NamesTXT: WideString;
I, Count: Integer;
Initialized, EmptyVars: Boolean;
begin
NamesTXT := WideGetCurrentDir + '\~temp_vars_names.txt';
If not Initialized then
begin
If not WideFileExists(NamesTXT) then FileWriteContent(NamesTXT, '');
If FileReadContent(NamesTXT)='' then EmptyVars:=True else EmptyVars:=False;
end;
If EmptyVars then
begin
FileAppendContent(NamesTXT, FileName + #13#10);
FileName := ':: Please do the Preview again ::';
end
else
begin
If not Initialized then
begin
NamesDB := WideSplitString(FileReadContent(NamesTXT), #13#10);
WideDeleteFile(NamesTXT);
end;
Count:=0
For I:=0 to length(NamesDB)-1 do
begin
If WideSameText(FileName, NamesDB[i]) then Count := Count + 1;
end;
If Count>1 then FileName := ':THIS FILE NEEDS SERIALIZATION: ' + FileName;
end;
Initialized := True;
end.
Gives some problems if you add more files to the list when it is asking for the new preview, but beeing careful that all files passes both steps it works ok.
Last edited by SafetyCar (2010-05-23 13:00)
If this software has helped you, consider getting your pro version. :)
Offline