Multi Commander > Script
Recursive file search
Suncatcher:
I have need for script which would find all *dsl and *.lsd files in directory including subdirectories and select those folders which contain them. I wrote this script which, however, doesn't work.
--- Code: ---@var $file = FindFiles("D:\downloads\Dicts_unpacked\\*");
@var $n;
for( $n = 0; $n < arrayCount($file); $n++)
{
@var $is = IsFolder($file[n]);
if($is == 1)
{
@var $infiles = FindFiles($file[n] ^ "*.lsd");
if(arrayCount($infiles) > 0)
{
@var $num = SetSourceSelected( $file[n] , 1);
}
@var $infiles = FindFiles($file[n] ^ "*.dsl");
if(arrayCount($infiles) > 0)
{
@var $num = SetSourceSelected( $file[n] , 1);
}
}
}
--- End code ---
I get error on the 4th line: Script engine error - Line : 4, Error : -1 => Code : "$n = IsFolder($file[n])"
However, if I hard code this line, e.g IsFolder($file[0])) the IsFolder function works smoothly.
What am I doing wrong? Maybe, I misunderstand some fundamental concept?
P.S. Is there any function for recursive file search?
Mathias (Author):
--- Quote from: Suncatcher on February 17, 2016, 14:46:50 ---
--- Code: --- @var $is = IsFolder($file[n]);
--- End code ---
--- End quote ---
you are missing a $ before the "n"
try
@var $is = IsFolder($file[$n]);
same error in the other places where $n is accessed
--- Quote from: Suncatcher on February 17, 2016, 14:46:50 ---P.S. Is there any function for recursive file search?
--- End quote ---
No, you have to do it your self in the script.
Suncatcher:
Thank you, it was a dumb mistake, and finally I was able to fulfill my task.
I don't know whether it will be useful for anybody (selection of folders based on filetypes they contain), but I will just put the script here.
--- Code: ---@var $file = FindFiles("D:\some\path\\*");
@var $n;
for( $n = 0; $n < arrayCount($file); $n++)
{
@var $is = IsFolder($file[$n]);
if($is == 1)
{
@var $inlsdfiles = FindFiles($file[$n] ^ "*.lsd");
@var $indslfiles = FindFiles($file[$n] ^ "*.dsl");
if(arrayCount($inlsdfiles) > 0)
{
@var $arr[] = PathGetParts($file[$n]);
@var $path[] = {};
arrayAdd($path, $arr[2]);
@var $num = SetSourceSelected($path, 0);
}
if(arrayCount($indslfiles) > 0)
{
@var $arr[] = PathGetParts($file[$n]);
@var $path[] = {};
arrayAdd($path, $arr[2]);
@var $num = SetSourceSelected($path, 0);
}
}
}
--- End code ---
Maybe, it could be done in a more beautiful way, but the clumsiness of this script language reads off the scale. I had a choice between Batch script, Bash script and Your script during evaluating this task, and I assume, I made the wrong choice :)
Suncatcher:
Several other critical points that should be emphasized:
1. No complex conditions can be built in IF clause.
--- Code: ---if(A == B OR (B == C AND D == E) ) {}
--- End code ---
Or I am mistaken? I didn't find anything in documentation.
2. The behavior of script interpreter with IF clause is undefined. One time it threw the exception with totally correct piece which is on the picture 1.
Another time it behaved itself totally unexpectedly with this piece of code.
--- Code: --- if(arrayCount($inlsdfiles) == 0)
{
}
else if(arrayCount($indslfiles) == 0)
{
}
else
{
@var $arr[] = PathGetParts($file[$n]);
@var $path[] = {};
arrayAdd($path, $arr[2]);
@var $num = SetSourceSelected($path, 1);
}
--- End code ---
During rendering this piece, having found false condition in main IF it skipped all other ELSE clauses and proceeded to the next loop iteration.
3. The collation of the real directories differs from the collation of array that FindFiles() function returns as result (see picture 2). And that's awkward.
4. The arrays cannot be initialized as empty ones. E.g.
--- Code: ---@var $arr = {};
--- End code ---
Even if you write like this it inserts empty array member.
5. The arrays cannot be initialized with variables. E.g.
--- Code: ---@var $arr = {$ini[$n], $ini[$n+1], $ini[$n+2], ...};
--- End code ---
Only with literals and it's poor.
So, the script language, as well as debugger, is still very raw for real work. IMHO.
Mathias (Author):
--- Quote from: Suncatcher on February 17, 2016, 21:26:24 ---Thank you, it was a dumb mistake, and finally I was able to fulfill my task.
I don't know whether it will be useful for anybody (selection of folders based on filetypes they contain), but I will just put the script here.
--- Code: ---@var $file = FindFiles("D:\some\path\\*");
@var $n;
for( $n = 0; $n < arrayCount($file); $n++)
{
@var $is = IsFolder($file[$n]);
if($is == 1)
{
@var $inlsdfiles = FindFiles($file[$n] ^ "*.lsd");
@var $indslfiles = FindFiles($file[$n] ^ "*.dsl");
if(arrayCount($inlsdfiles) > 0)
{
@var $arr[] = PathGetParts($file[$n]);
@var $path[] = {};
arrayAdd($path, $arr[2]);
@var $num = SetSourceSelected($path, 0);
}
if(arrayCount($indslfiles) > 0)
{
@var $arr[] = PathGetParts($file[$n]);
@var $path[] = {};
arrayAdd($path, $arr[2]);
@var $num = SetSourceSelected($path, 0);
}
}
}
--- End code ---
Maybe, it could be done in a more beautiful way, but the clumsiness of this script language reads off the scale. I had a choice between Batch script, Bash script and Your script during evaluating this task, and I assume, I made the wrong choice :)
--- End quote ---
Batch would be messier and you can't do selection from that..
But you can split it up into functions making it cleaner..
Navigation
[0] Message Index
[#] Next page
Go to full version