Resource

Resource Basics

Resource Name Rename Extension With XMP Files to standard XMP Files
Resource Version 1.0
Category Metadata
Downloads 499
Release Date 3/20/2024 1:08:29 AM
 

Resource Details

Description This script will rename existing "Extension+XMP" sidecar files to XMP file names that follow the XMP standard naming. Use with care!

e.g. IMG0001.NEF.XMP becomes IMG0001.XMP
Installation Instructions In the application, right click on a thumbnail and select Run Script from Repository -> Metadata -> Delete sidecar XMP file
Usage Instructions na
Changes in this version na
Special Requirements
 

Author Information

Author Name IDimager
 

Script


  procedure RenameXMPSidecarFor(AImage: TImageItem);
  var
    AXmp: TXMP;
    AOldSidecar, ANewSidecar: WideString;
  begin
    AOldSidecar := AImage.FileName + '.xmp';
    ANewSidecar := WideChangeFileExt(AImage.FileName, '.xmp');

    if WideFileExists(AOldSidecar) and (not WideFileExists(ANewSidecar)) then
      WideRenameFile(AOldSidecar, ANewSidecar);
  end;

var
  i: Integer;
  AList: TStringList;
  AImage: TImageItem;
  ASidecar: WideString;
  APro: TxomProgress;
begin
  if Selected.Count = 0 then
  begin
    Say2('No images selected.', 'Select one or more thumbnails and try again.');
    exit;
  end;

  AList := TStringList.Create;
  for i := 0 to Selected.Count - 1 do
  begin
    AImage := Selected.Items[i];
    ASidecar := AImage.FileName + '.xmp';
    if WideFileExists(ASidecar) then
      AList.AddObject(AImage.FileName, AImage);
  end;

  if AList.Count > 0 then
  begin
    if AskYN('There are ' + IntToStr(AList.Count) + ' images found in your selection that have extensions with XMP sidecar files.' + CrLf2 +
             'Do you want to rename these XMP files to the standard XMP file names?' + CrLf2 +
             'WARNING: This cannot be undone.')
    then
    begin
      APro := TxomProgress.Create(nil);
      APro.Caption := 'Rename sidecar XMP file';
      APro.Max := AList.Count;
      for i := 0 to AList.Count - 1 do
      begin
        AImage := AList.Objects[i];

        APro.Pos := i + 1;
        APro.ProgressText := AImage.FileNameOnly;
        if APro.Cancel then
          break;
        RenameXMPSidecarFor(AImage);
      end;
      APro.Free;
    end;
  end
  else
    Say('No sidecar XMP files found.');

  AList.Free;
end;