Delete Stray or Orphaned XMP Sidecar Files

When working with RAW files there's typically an accompanying XMP file storing information that pertains to the image (such as GPS coordinates and color corrections). Unfortunately, deleting the RAW file in the vast majority of applications and operating systems doesn't result in deletion of the corresponding .xmp file, leaving orphaned sidecar files in the directory without an accompanying image.

The (Windows XP/Vista/7) solution to deleting unwanted XMP sidecar files is to create a little program. It takes just a minute or two:

How to Automatically Delete Stray XMP Sidecar Files:

  1. open notepad and save the following text as strayXMP.bat
    @ECHO OFF
    ECHO Deletes orphan XMP-files in this directory:
    CD
    ECHO (That are XMP-files without corresponding .NEF-file)
    ECHO.
    ECHO Press Ctrl-Break to stop or
    PAUSE
    FOR /f "tokens=*" %%Z IN ('dir /b *.xmp') do CALL DELXMP.BAT %%~spZ%%~nZ
    ECHO ALL DONE
    PAUSE
  2. Open notepad and save the following text as delXMP.bat
    @ECHO OFF
    IF EXIST %1.NEF echo %1.NEF exists, skipping
    IF NOT EXIST %1.NEF ECHO No %1.NEF, deleting
    IF NOT EXIST %1.NEF DEL %1.xmp
  3. If your RAW files aren't Nikon NEF, replace the five instances of it in step #2 with 'CR2' or whatever RAW file extension your camera uses. Save the file.
  4. Windows must be able to "see" delXMP.bat and strayXMP.bat from any directory on the system. To make that possible the easiest way is to place both files in your \Windows directory. Alternatively, place only delXMP.bat in the Windows directory and copy strayXMP.bat to the directory you wish to purge orphaned sidecar files from.
  5. If you placed both files in the Windows directory, you'll be able to run the purge process by typing "strayxmp" from any directory you navigate to in the command window (tip: Vista and Windows 7 makes this easy). If you'd rather double-click on an icon instead of opening the command window manually, simply copy strayXMP.bat to the directory you'd like to remove sidecar files from and double-click to file to start the process.
  6. Finally, if you'd like to process multiple directories simultaneously, save the following as allstrayXMP.bat to a directory of your choosing. When run it will include all its subdirectories in the search for orphaned sidecar files.
    @ECHO OFF
    ECHO Deletes orphan XMP-files in this directory, and all of its subdirectories:
    CD
    ECHO (That are XMP-files without corresponding .NEF-file)
    ECHO.
    ECHO Press Ctrl-Break to stop or
    PAUSE
    FOR /R "tokens=*" %%Z IN ('dir /b *.xmp') do CALL DELXMP.BAT %%~spZ%%~nZ
    ECHO ALL DONE
    PAUSE

Enjoy!

Related Catagories: Photography

Delete Stray or Orphaned XMP Sidecar Files Photos:

Delete Stray or Orphaned XMP Sidecar Files Videos:

Submitted Links and Comments about Delete Stray or Orphaned XMP Sidecar Files:

Gravatar Avatar

Ben

July 27th, 2010

I easily modified this to fit my needs: deleting orphan RAW files that have no corresponding JPGs. Thanks for the code.

Submit a New Link or Comment:

Note: Comments are open to everyone. To reduce spam and reward regular contributors, only submissions from first-time commenters and/or those containing hyperlinks are moderated, and will appear after approval. Relevant content contribution to this article is encouraged; however, off-topic and "me too" remarks are subject to pruning. Your e-mail address will never be publicly disclosed or abused.