Info→tips

XPM without raw files

as stated in my other article, I am used to work with xmp-files when working with lightroom.
For the reasons, why, read the corresponding article on

when deleting an image via lightroom, the xmp files goes away as well. but I also use faststone viewer to quickly select/delete images. This tool does not show the raw file, nor takes into account the LR changes out of the XMP (it uses the embedded jpg-format), but it is much faster than LR, and thus much faster do just delete the 'garbage'.
when doing this before importing into LR, no problem, there are no XMP's yet, but sometimes I use it after already having done things in LR, and then the XMP remains there.

I looked on the internet (where 'everyting' can be found), and found a BAT-file for doing the cleanup of these orphan xmp's. but I changed the bat-file to make it more user friendly.
  • you can put this file in any location and run it from there, it will prompt for a directory to treath
  • the subroutines are embedded, thus there is only one bat-file
  • you can do a simulation-run, doing everything but the delete



  • the code.
    copy the text, and save it somewhere as a .bat, e.g. cleanuporphans.bat


    @ECHO OFF 
    set scriptdir=%cd%
    set rawext=%1
    set mainext=%2
    IF "%rawext%"=="" set rawext=NEF
    IF "%mainext%"=="" set mainext=XMP
    ECHO This will treat all %mainext%-files, and delete them if no corresponding %rawext%-file
    set topdir=
    set recdir=
    CALL :promptsettings 
    if %errorlevel% GEQ 1 exit 8
    ECHO ==============================================
    echo OK, here we go............. 
    echo command used:
    echo FOR %recdir% %%f in (*.%mainext%) do CALL :delorphans "%%~pf\%%~nf" "%rawext%"
    ECHO ==============================================
    set /a cntfiles=0
    set /a cntkeep=0
    set /a cntdel=0
    set scriptdir=%cd%
    pushd "%topdir%"
    echo start-directory %cd%
    FOR %recdir% %%f in (*.%mainext%) do CALL :delorphans "%%~pf\%%~nf" "%rawext%"
    popd
    echo treated %cntfiles% files
    echo     kept %cntkeep%
    echo     deleted %cntdel%
    ECHO ==============================================
    echo All done.
    ECHO ==============================================
    PAUSE
    goto :eof
    
    
    :promptsettings
    choice /C yn /T 30 /d y /m "SIMULATION (y/n)" 
    if ERRORLEVEL 1 set simrun=echo SIMULATION -
    if ERRORLEVEL 2 set simrun=
    %simrun%
    :dirprompt
    set topdir=
    SET /P topdir=enter directory to handle (e.g. d:/fotos) or empty (cancel): 
    IF "%topdir%"=="" exit /B 8
    IF NOT EXIST "%topdir%" goto dirprompt
    :subprompt
    choice /C ync /T 30 /d c /m "also include subdirectories (y/n), or c(ancel)" 
    if ERRORLEVEL 1 set recdir=/R
    if ERRORLEVEL 2 set recdir=
    if ERRORLEVEL 3 exit /B 8
    echo ============================================================
    ECHO Delete orphan %mainext%-files
    ECHO     That are %mainext%-files without corresponding .%rawext%-file 
    ECHO directory: %topdir% 
    if "%recdir%" NEQ "" echo      also including subdirectories (%recdir%) !!!
    echo ============================================================
    ECHO Press Ctrl-C to stop or any other key to continue !!!!!!!!!!!!
    pause
    exit /B 0
    
    
    :delorphans
    @ECHO OFF 
    IF "%2"=="" exit 8
    rem echo --file: %1
    set /a cntfiles=%cntfiles%+1
    set xmpfile=%1.%mainext%
    set rawsuff=%2%
    IF EXIST %1.%rawsuff% goto keepxmp
    echo %xmpfile% does not have corresponding %rawsuff%, deleting %mainext%-file
    %simrun% del %xmpfile%
    set /a cntdel=%cntdel%+1
    exit /B 4
    :keepxmp
    set /a cntkeep=%cntkeep%+1
    rem echo %1.%rawsuff% exists, keeping %xmpfile%  
    exit /B 0
    


    © Marcel Quintelier.