Author Topic: Advanced Selection with Script  (Read 17825 times)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4484
    • View Profile
    • Multi Commander
Advanced Selection with Script
« on: July 18, 2015, 15:16:05 »
As of build 1964 you can now do advanced selection with script easier.

There are two new functions sets that allow for this.

The first new functions that make this possible are GetSourceItems() / GetTargetItems()
They return a array with all items from the source or target panel.
The file paths returned are only the filenames. So they are relative to current path of source/target.
( You can get current path with GetSourcePath()/GetTargetPath() )

You can get FULL path by sending 1 as parameter  ( GetSourceItems(1); ) But for the selection example below we do not want that since SetSourceSelected(..) require names only. not complete paths.

The other new function is SetSourceSelected(...) / SetTargetSelected(..)
They accept an array with names of files that it will match and set as selected. the second parameter is optional and if it is 1 it will clear all existing selections first. This is the default behavior so if you want to clear the second parameter is not needed. You really only need to set it to 0 if you want to ADD selections without clearing out current selections.
Eg
SetSourceSelect( $arr );  // Clear Selection before settings them
SetSourceSelect( $arr, 1 );  // Clear Selection before settings them
SetSourceSelect( $arr , 0); // Add selection. Do not clear


Example.
Lets say we want to select all audio files that have a bitrate of 320 and more

Code: [Select]
@var $currentPath = GetSourcePath();
@var $Items = GetSourceItems();
@var $count = arrayCount($Items);
@var $selectItems[];
@var $curItem;
@var $fullFilename;

// Loop all items in the $Items array
for( $n = 0; $n < $count; $n++)
{
  $curItem = $Items[$n];

  $fullFilename = $currentPath ^ $curItem;
  @var $bitrate = GetFileProp($fullFilename, "MCAudioProp.bitrate");
  if($bitrate >= 320)
  {
      arrayAdd($selectItems, $curItem );
  }
}

// Selected all the items in the $selectItems array
@var $ClearSelectedFirst = 0;
SetSourceSelected($selectItems, $ClearSelectedFirst);
(However since every file is accessed and bitrate is extracted from metadata inthe file. it can takes some time to run this script if there are a lot of audio files.)