Resource

Resource Basics

Resource Name Relocate Single File
Resource Version 1.0
Category Catalog
Downloads 942
Release Date 5/2/2014 4:14:04 PM
 

Resource Details

Description This script allows you to relocate a single file by selecting its new location from the hard drive.
Installation Instructions Download the file
Usage Instructions 1. Select the file that you want to relocate
2. Select Tools -> Scripter
3. Open the downloaded script file
4. Run the script
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Script

var
  AImage: TImageItem;
  ACatItem, ACatItem2: TCatalogItem;
  ADlg: TOpenDialog;
  ADir: WideString;
begin
  if Selected.Count > 1 then
  begin
    Say ('This script only works for a single selected file');
    exit;
  end;
  AImage := Selected.Items[0];

  ACatItem := TCatalogItem.Create(nil);

  if Catalog.FindImageCombined(AImage, ACatItem, False, vptNone) then
  begin
    ADlg := TOpenDialog.Create(nil);
    ADir := ReadFromRegistry('Scripts\RelocateFile', 'LastPath', WideExtractFilePath(AImage.FileName));
    ADlg.InitialDir := UTF8Encode(ADir);
    if ADlg.Execute then
    begin
      ACatItem.FileName := ADlg.FileName;
      ACatItem.UpdateFileInfo;

      if not Catalog.FindItemCombined2(ACatItem, ACatItem, False, vptNone) then
      begin
        Catalog.StoreItemToDataBase(ACatItem, False);
        Say (AImage.FileName + CrLf2 + ' is relocated to ' + CrLf2 + ACatItem.FileName);
        WriteToRegistry('Scripts\RelocateFile', 'LastPath', WideExtractFilePath(ACatItem.FileName))
      end
      else
        Say ('This image is already in the catalog');
    end;
    ADlg.Free;
  end
  else
    Say ('File not in catalog');

  ACatItem.Free;
end;