Resource

Resource Basics

Resource Name Move Files to Folder
Resource Version 1.0
Category File System
Downloads 1026
Release Date 3/28/2024 2:05:56 PM
 

Resource Details

Description This script moves the files for the selected thumbnails to a folder of choice.
Use with care!
Installation Instructions na
Usage Instructions 1. Select one or more Thumbnails
2. Right click on a selected thumbnail
3. Select "Run script from repository"
4. Select File system -> Move Files to Folder'
Changes in this version na
Special Requirements
 

Author Information

Author Name IDimager
 

Script


  function HandleImageItem(ADir: WideString; AImage: TImageItem): Boolean;
  var
    ATargetFileName: WideString;
    ACatItem: TCatalogItem;
  begin
    result := False;
    ATargetFileName := ADir + AImage.FileNameOnly;

    if WideSameText(ATargetFileName, AImage.FileName) then
      exit;

    if WideFileExists(ATargetFileName) then
      exit;

    result := AImage.MoveFile(ATargetFileName, True, False);

    // if succeeded then update the catalog as well
    if result then
    begin
      ACatItem := TCatalogItem.Create(nil);
      try
        PublicCatalog.RenameFileName(
          AImage.FileName,
          AImage.MediumType,
          AImage.MediumName,
          AImage.MediumSerial,
          ATargetFileName,
          ACatItem
        );
      finally
        ACatItem.Free;
      end;
    end;
  end;

var
  ADir: WideString;
  i, AHit: Integer;
  AProgress: TxomProgress;
begin
  if Selected.Count = 0 then
  begin
    Say('Select at least one thumbnail to move');
    exit;
  end;
  ADir := ReadFromRegistry('MoveToFolder', 'Dir', WideExtractFilePath(Selected.Items[0].FileName));
  if not WideSelectDirectory('Move to folder', 'Select target directory', ADir) then
    exit;

  WriteToRegistry('MoveToFolder', 'Dir', ADir);

  if not AskYN('Are you sure that you want to move the ' + IntToStrW(Selected.Count) + ' selected files to folder ' + ADir + '?' + CrLfW + ' ') then
    exit;

  ADir := WideIncludeTrailingBackslash(ADir);

  AProgress := TxomProgress.Create(nil);
  try
    AProgress.Caption := 'Move Files to Folder';

    AHit := 0;
    for i := 0 to Selected.Count - 1 do
    begin
      AProgress.ProgressText := Selected.Items[i].FileNameOnScreen;
      AProgress.Pos := i + 1;
      if AProgress.Cancel then break;

      if HandleImageItem(ADir, Selected.Items[i]) then
        Inc(AHit);
    end;
  finally
    AProgress.Free;
  end;

  Say(IntToStrW(AHit) + ' files have been moved to ' + ADir);
end;