SCRIPTING: move file and update catalog

Post Reply
lauff
Posts: 14
Joined: 19 Dec 09 10:32

SCRIPTING: move file and update catalog

Post by lauff » 02 Jun 18 14:31

Hi,

I am trying a pretty simple "move file to another directory".

The file is being moved, but the catalog is not update.

Code: Select all

procedure HandleItem (AImage: TImageItem);
var
  ANewFile: WideString;
begin
     ANewFile := AnsiReplaceStr(AImage.FileName,'\photo\','\photo\__RAW\');
     ANewFile := AnsiReplaceStr(ANewFile,'\_RAW\','\');

     if AImage.MoveFile (ANewFile, False, True, True) then
      begin
         Catalog.RenameImage(AImage, ANewFile);
      end;
end;

var
  i: Integer;
begin
  if Selected.Count = 0 then
  begin
    Say('No images selected');
    exit;
  end;

  if not Ask('Are you sure you want to move ' + IntToStr(Selected.Count) + ' selected images?') then
    exit;

  Progress.Cancel := False;
  Progress.Max := Selected.Count;
  Progress.Pos := 0;
  Progress.Show;

  for i := 0 to Selected.Count - 1 do
  begin
    Progress.Pos := i + 1;
    if Progress.Cancel then
      break;

    HandleItem (Selected.Items[i]);
  end;

  //InvalidateCollection();

  Progress.Hide;

  if Progress.Cancel then
    Say ('Cancelled')
  else
    Say ('Finished');
end;              

Any idea?

Btw, I still haven't found a good resource to get help for scripting. Would you please provide a good link?

Thanks,
Markus

Post Reply