Resource

Resource Basics

Resource Name Search by Partial File Name
Resource Version 2.0
Category Search Scripts
Downloads 1108
Release Date 4/24/2018 8:45:33 AM
 

Resource Details

Description This script searches through the entire Photo Supreme Catalog for a specific part of the file name.
Installation Instructions 1. Download the script to your hard drive
2. Select Tools -> Scripter
3. Load the Script as saved in step 1
4. Run the script
Usage Instructions After starting the script, you can enter a part of a file name to search for.
Changes in this version v2.0 Added option to search in full file part
v1.3 Made compatible with V5
Special Requirements Photo Supreme V5
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 SearchFilePart.png
 

Script

var
  ATextBox: TvxTextBox;
  AStartsWith: TvxCheckBox;
  ASearchFilePath: TvxCheckBox;

  function CreateForm: TvxSceneForm;
  var
    ARoot: TvxVisualObject;
    ALabel: TvxLabel;
  begin
    result := TvxSceneForm.Create(nil);
    result.Caption := UTF8Encode('Search by Filename part');
    result.Position := poScreenCenter;
    result.Height := 130 * result.DPIFactor;

    ARoot := result.Root;

    ALabel := TvxLabel.Create(ARoot);
    ALabel.Text := 'Enter filename part to search for:';
    ALabel.TextAlign := vgTextAlignNear;
    ALabel.Padding.Left := 10;
    ALabel.Padding.Top := 10;
    ALabel.Align := vaTop;
    ARoot.AddObject(ALabel);

    ATextBox := TvxTextBox.Create(ARoot);
    ATextBox.Padding.Left := 10;
    ATextBox.Padding.Right := 10;
    ATextBox.Padding.Top := 10;
    ATextBox.Align := vaTop;
    ARoot.AddObject(ATextBox);

    AStartsWith := TvxCheckBox.Create(ARoot);
    AStartsWith.Padding.Left := 10;
    AStartsWith.Padding.Right := 10;
    AStartsWith.Padding.Top := 10;
    AStartsWith.Align := vaTop;
    AStartsWith.Text := 'Should start with';
    ARoot.AddObject(AStartsWith);

    ASearchFilePath := TvxCheckBox.Create(ARoot);
    ASearchFilePath.Padding.Left := 10;
    ASearchFilePath.Padding.Right := 10;
    ASearchFilePath.Padding.Top := 10;
    ASearchFilePath.Align := vaTop;
    ASearchFilePath.Text := 'Search in full file path';
    ARoot.AddObject(ASearchFilePath);
  end;

  procedure SearchFileName(ASearchString: WideString);
  var
    ADs: TDBXOMClientDataSet;
    AData: TidElement;
    AColl: TImageCollection;
  begin
    ADs := PublicCatalog.NewDataset;

    ADs.CommandText := 'select ' + PublicCatalog.FullColumnList('') + ' ' +
                       'from   v_catalogitem ' +
                       'where  ' + iif(ASearchFilePath.IsChecked, 'FullFileName', 'FileName') + ' like ''' + iif(AStartsWith.IsChecked, '', '%') + ASearchString + '%' + ''' ' +
                       'UNION ALL ' +
                       'select ' + PublicCatalog.FullColumnList('') + ' ' +
                       'from   v_catalogitemversion ' +
                       'where  ' + iif(ASearchFilePath.IsChecked, 'FullFileName', 'FileName') + ' like ''' + iif(AStartsWith.IsChecked, '', '%') + ASearchString + '%' + ''' ' +
                       '';
    ADs.LockType := ReadLockType;
    ADs.OpenSet
    try
      AData := TidElement.Create(nil);
      try
        PublicBroadCast(nil, 'OpenNewTab', nil);
        PublicBroadCastRequest(nil, 'ActiveCollection', AData);
        AColl := AData.Data;
        AColl.Clear;
        AColl.Items.AddDataset(ADs, True);
        PublicBroadCast(nil, 'RefreshActiveCollection', nil);
      finally
        AData.Free;
      end;
    finally
      ADs.CloseSet;
    end;

    PublicCatalog.FreeDataset(ADs);
  end;

var
  AForm: TvxSceneForm;
begin
  AForm := CreateForm;
  try
    ATextBox.Text := ReadFromRegistry('', 'scSearchFileName.LastText', '');
    AStartsWith.IsChecked := ReadFromRegistry('', 'scSearchFileName.LastStartsWith', 0) = 1;
    ASearchFilePath.IsChecked := ReadFromRegistry('', 'scSearchFileName.SearchFilePath', 0) = 1;

    AForm.PrepareModal([mbOK, mbCancel]);
    AForm.ShowModal;
    if AForm.ModalResult = mrOk then
    begin
      WriteToRegistry('', 'scSearchFileName.SearchFilePath', iif(ASearchFilePath.IsChecked, 1, 0));
      WriteToRegistry('', 'scSearchFileName.LastStartsWith', iif(AStartsWith.IsChecked, 1, 0));
      WriteToRegistry('', 'scSearchFileName.LastText', ATextBox.Text);
      SearchFileName(ATextBox.Text);
    end;
  finally
    AForm.Free;
  end;
end;