You are not logged in.
I want to add an PascalScript as first, or as last rule.
This PascalScript should be executed only one time (not one time for every file, but one time for an whole preview/renaming job).
I would use this for initial (e.g.: get list of files) and finalizing (e.g.: delete folder) tasks.
To implement this, i imagine a keyword inside the script would work?
If found {RunOneTimeOnly} on first line this feature would be enabled.
(better of course if this could be on any line, to leave the first line for comments)
.
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
Once Denis talked about implementing a function that could read and change names of not only the file being processed but any other.
I don't know where I read it, and I don't get to find about it...
It was something more or less like (I'm inventing this) GetApplicationFileName(Index); SetApplicattionFileName(Index); GetIndex(); GetTotalNumberOfFiles();
If we had this we could do "If (GetIndex() = GetTotalNumberOfFiles()) then"
But I don't know if they are still on Denis plans.
---------
EDIT: Maybe the GetIndex() was not on the plans but it can be done just with a counter to know where we are.
Last edited by SafetyCar (2013-01-26 18:56)
If this software has helped you, consider getting your pro version. :)
Offline
The internal design doesn't let me easily and cleanly add this functionality without a bit of rework.
However, we can simulate this behavior using something like GetCurrentFileIndex and GetTotalNumberOfFiles functions, as suggested.
I'll add these functions.
Offline
I think that will work pretty fine. Thank you all for your support.
Top most script in rules list:
begin
if (GetCurrentFileIndex = 1 ) then
begin
//initializing code here, executed only once
end;
end.
Very last script in rules list:
begin
if (GetCurrentFileIndex = GetTotalNumberOfFiles) then
begin
//Cleaning up code here, executed only once
end;
end.
Also useful for:
FileName := IntToStr(GetCurrentFileIndex) +' of ' + IntToStr(GetTotalNumberOfFiles) + ' ' + FileName;
Pad := length(GetTotalNumberOfFiles);
That reminds me to modulo. Can we use this too?
if (modulo(GetCurrentFileIndex, 2) = 0) then
skip;
if (modulo(GetCurrentFileIndex, 10) = 0) then
counter := 0;
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
I've added GetCurrentFileIndex and GetTotalNumberOfFiles functions and info on the Wiki: ReNamer:Pascal_Script:Functions#Application
Please test!
Offline
Regarding modulo, you can use DivMod function or the actual mod operation, e.g.:
begin
if (GetCurrentFileIndex mod 2) = 0 then
FileName := FileName + ' (even)'
else
FileName := FileName + ' (odd)';
end.
There is not "skip" functionality yet.
Offline
beta 27. Jan. 2013
first tests works as indented, good work.
Initialize only once:
begin
if(GetCurrentFileIndex=1)then
begin
if(GetTotalNumberOfFiles > 1000)then
begin
if(DialogYesNo('Do you wanna start?')=False) then
ShowMessage('quit')
else
ShowMessage('continue')
end;
end;
end.
Add text "<file No.> of <fileS>"
var
pad:integer;
num:string;
begin
// Add your code here
pad := length(IntToStr(GetTotalNumberOfFiles));
num := IntToStr(GetCurrentFileIndex);
while length(num) < pad do num := '0'+num;
FileName := num + ' of ' + IntToStr(GetTotalNumberOfFiles) + ' ' + FileName;
end.
Differ between every second file:
begin
if (GetCurrentFileIndex mod 2) = 0 then
FileName := WideExtractBaseName(FileName) + ' (even)'+ WideExtractFileExt(FileName)
else
FileName := WideExtractBaseName(FileName) + ' (odd)' + WideExtractFileExt(FileName);
end.
Serialize every four files from 1 to 4:
var
i:integer;
s:string;
begin
s:=IntToStr(i+1);
FileName := WideExtractBaseName(FileName) + '_' + s + WideExtractFileExt(FileName)
inc(i);
if(i mod 4) = 0 then
i := 0;
end.
Clean up at the end on the last file:
>> BUT this dialog is shown before the last file is shown in the NewName column.
>> So i guess i can't delete the folder yet. Have to test this later the day.
begin
if(GetCurrentFileIndex=GetTotalNumberOfFiles)then
ShowMessage(IntToStr(GetCurrentFileIndex)
+ ' out of '+IntToStr(GetTotalNumberOfFiles)+' done!'+#10+#10
+ 'It''s save now to delete the old folder...');
end.
Proof of concept:
German.txt 01 of 14 German (odd)_1.txt
Croatian.txt 02 of 14 Croatian (even)_2.txt
Bulgarian.txt 03 of 14 Bulgarian (odd)_3.txt
Russian.txt 04 of 14 Russian (even)_4.txt
Turkish.txt 05 of 14 Turkish (odd)_1.txt
French.txt 06 of 14 French (even)_2.txt
Polish.txt 07 of 14 Polish (odd)_3.txt
Russian (Latin).txt 08 of 14 Russian (Latin) (even)_4.txt
Russian (Alt).txt 09 of 14 Russian (Alt) (odd)_1.txt
Serbian (Cyrillic).txt 10 of 14 Serbian (Cyrillic) (even)_2.txt
Serbian (Latin).txt 11 of 14 Serbian (Latin) (odd)_3.txt
Czech.txt 12 of 14 Czech (even)_4.txt
Romanian.txt 13 of 14 Romanian (odd)_1.txt
Ukrainian.txt 14 of 14 Ukrainian (even)_2.txt
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
Nice, just before downloading I started to think about a possibility of conflict with the unchecked files. But there have not been such problems, the total_files are the total_checked and there has been no problem nor with first-file nor with last-file.
So, it looks like very solid to me.
If this software has helped you, consider getting your pro version. :)
Offline
the total_files are the total_checked
Just for reference, since i asked myself is this "selected only" is good or not,
here is the code to get the total amount of files of an folder (not only the selected onces):
var
FilesArray:TStringsArray;
TotalFilesOnFolder:String;
begin
if(GetCurrentFileIndex=1)then
begin
//WideScanDirForFiles(Dir, Files, Recursive, IncludeHidden, IncludeSystem, Mask);
WideScanDirForFiles(WideExtractFilePath(FilePath), FilesArray, false, false, false, '*');
TotalFilesOnFolder := IntToStr(length(FilesArray));
ShowMessage('Files in folder: '+ TotalFilesOnFolder + #10
+ 'Selected files: ' + IntToStr(GetTotalNumberOfFiles));
end;
end.
Result:
---------------------------
ReNamer
---------------------------
Files in folder: 14
Selected files: 11
---------------------------
OK
---------------------------
?
So should not GetTotalNumberOfFiles
be called something like
GetTotalNumberOfSelFiles
GetTotalNumberOfSelectedFiles
GetNumberOfSelectedFiles
?
Just to be clear and prevent from being mistaken?
.
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
So should not GetTotalNumberOfFiles
be called something like
GetTotalNumberOfSelFiles
GetTotalNumberOfSelectedFiles
GetNumberOfSelectedFiles?
Just to be clear and prevent from being mistaken?
That last one looks good to me, and yes, probably is better to have the name as closest to the reality as possible.
If this software has helped you, consider getting your pro version. :)
Offline