Resource

Resource Basics

Resource Name Replace image with selected file
Resource Version 1.0
Category Catalog
Downloads 779
Release Date 8/24/2020 3:10:03 PM
 

Resource Details

Description This script will relocate a file to a different file name.
Installation Instructions 1. Download the script to your local drive
Usage Instructions 1. Select one thumbnail
2. Start the Tools->Scripter
3. Load the downloaded script
4. Run the script
5. Select the new file name
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Script

{
  This script will relocate a file to a different file name.

  Original Author: IDimager
  Version History:
    1.0; 24 aug 2020;
         initial version
}

  function SelectNewFileFor(AFileName: WideString): WideString;
  begin
    result := '';
    OpenDialog.InitialDir := WideExtractFilePath(AFileName);
    OpenDialog.Title := 'Select New File';
    OpenDialog.Filter := vxBitmapFormats.FileFilterString;
    if OpenDialog.Execute then
      result := OpenDialog.FileName;
  end;

  function RelocateImage(AImg: TImageItem): Boolean;
  var
    ACatItem: TCatalogItem;
    ANewFileName: WideString;
  begin
    result := False;
    ACatItem := TCatalogItem.Create(nil);
    try
      if not PublicCatalog.FindItemCombinedByGUID(AImg.GUID, ACatItem) then
      begin
        Say('Image not found in catalog. Please try again.');
        exit;
      end;

      ANewFileName := SelectNewFileFor(ACatItem.FileName);
      if (ANewFileName <> '') and (not WideSameText(ACatItem.FileName, ANewFileName)) then
      begin
        if AskYN ('Are you sure your want to relocate ' + ACatItem.FileName + ' to ' + ANewFileName) then
        begin
          result := PublicCatalog.RelocateFile(ACatItem.FileName, ACatItem.MediumType, ACatItem.MediumName, ACatItem.MediumSerial, ANewFileName, ACatItem);
          if result then
          begin
            PublicBroadcastObjectText(nil, 'BuildThumbnailFor', ACatItem, nil, nil, '');
          end;
        end;
      end;
    finally
      ACatItem.Free;
    end;
  end;

begin
  if Selected.Count <> 1 then
  begin
    Say('Please select one thumbnail.');
    exit;
  end;

  if RelocateImage(Selected.Items[0]) then
    SendVisualFeedback('The file is relocated', 5000)
  else
    Say('Nothing changed');
end;