Multi Commander > Script

Select Same Name (Selected Files)

<< < (2/2)

Mathias (Author):
Ahh and if you do #2, then you might want to keep the "." in the filter so that it only matching files with different extension.
"filename.* filename2.* filename3.*"


pncdaspropagandas:
Thanks Mathias. I chose #1 and wrote the code:

@var $selected_files[] = GetSourceSelectedFileNames();
@var $all_files[] = GetSourceItems();
@var $same_name_files[];

@var $n;
@var $i;
@var $aux;
@var $aux2;
@var $selected_file_name_no_ext;

for($n = 0; $n < arrayCount($selected_files); $n++)
{
    $selected_file_name_no_ext = PathGetNamePart($selected_files[$n], 1);
    //LogAppInfo($selected_file_name_no_ext);
    for($i = 0; $i < arrayCount($all_files); $i++)
    {
        $aux = $all_files[$i];
        $aux2 = PathGetNamePart($aux, 0);
        //LogAppInfo('is ' + $aux2 + ' equal to ' + $selected_file_name_no_ext + ' ?');
      // For some reason if we compare using == instead of StrIsWildMatchNoCase, it always enters the if
        if (StrIsWildMatchNoCase($aux2, $selected_file_name_no_ext + '.*') == 1)
        {
            //LogAppInfo('equals');
            arrayAdd($same_name_files, $aux2);
        }
    }
   
}

 ;)
SetSourceSelected($same_name_files, 1);

Mathias (Author):
comparing with == can be tricky.. 
http://multicommander.com/docs/multiscript/functions/string#operator__
It also works like string compare in C/C++ and others. so a exact match is 0,

Also if both of the variables are not of string types, then automatic conversion comes into play that can create havoc.
So because of that it is better to use StrIsEqual / StrIsEqualNoCase  if you doing plain string compare

pncdaspropagandas:
wow, dind't see that... I thought == would work just like StrIsEqual. That's why I was having a headache with the code lol.

Thanks Mathias

Navigation

[0] Message Index

[*] Previous page

Go to full version