Frage

I always let my photocamera create a RAW-file ànd a JPG when taking photos. In my work-flow for "developing" the RAW-files, I first go through the JPG's and delete the JPG's from the photos which I don't want to process. I am then left with a directory with all the RAW-files and some of the JPG's:

  • DSC01864.ARW
  • DSC01865.ARW
  • DSC01866.ARW
  • DSC01867.ARW
  • DSC01868.ARW
  • DSC01868.JPG
  • DSC01869.ARW
  • DSC01869.JPG
  • DSC01870.ARW
  • DSC01870.JPG

I want to delete the RAW files for which I already deleted the JPG's. I have made a Windows batch-script for this, but for some reason it doesn't work; it deletes all the RAW-files :-(

The script:

@echo off
for %%F in (*.arw) do (
rem  echo %%~nF.jpg
  if exist {%%~nF.jpg} (
       echo File %%F is kept
       echo ------------------------
  ) else (
       del %%F
       echo File %%F is removed
       echo ------------------------
) )  
goto :EOF

I would like to now what I am doing wrong.... Apparently it doesn't recognise any JPG-file.

BTW, I used to have a working script for Bash (Linux), but I use DXO optics on Windows nowadays and am in need of a Windows-version. My bash-script:

#!/bin/bash
for rawfile in *.ARW
do
  jpegfile="`basename "$rawfile" .ARW`.JPG"
  if [ ! -e $jpegfile ]
  then
    /bin/rm -f $rawfile
  fi
done 
War es hilfreich?

Lösung

Your mistake is in line

  if exist {%%~nF.jpg} (

{ and } have no special meaning and are therefore read as literal characters.

So this IF condition checks for *.jpg files with { at beginning and }at end of the file name.

Simply remove { and } and your batch file works.

Andere Tipps

I have added the creation of a sub-directory called RAW and the deletion of all the original JPG's from the camera (as I don't use them anymore).

And I've creared a 2nd script which can be run after the "developing part" of the workflow. This 2nd script checks which RAW-files have been processed succesfully and moves those RAW-files and their configuration-file (made by DXO Optics) to the RAW sub-directory. I keep them archived in case I want to process them in the future again. In the main directory it leaves:

  • DSC01868_DxO.JPG
  • DSC01869_DxO.JPG
  • DSC01870_DxO.JPG

While in the RAW-subdirectory one gets:

  • DSC01868.ARW
  • DSC01868.ARW.dop
  • DSC01869.ARW
  • DSC01869.ARW.dop
  • DSC01870.ARW
  • DSC01870.ARW.dop

First script (Windows batch), which deletes the unwanted RAW's, creates a RAW-directory and deletes all original JPG's:

@echo off
for %%F in (*.arw) do (
  if exist %%~nF.jpg (
       echo File %%F is kept
       echo ------------------------
  ) else (
       del %%F
       echo File %%F is removed
       echo ------------------------
) )  
del *.jpg
mkdir RAW
goto :EOF

The 2nd script (Windows batch), which moves the RAW-files and their configuration files to the RAW-subdirectory:

@echo off
for %%F in (*.arw) do (
  if exist %%~nF_DxO.jpg (
       move %%F RAW\
       move %%F.dop RAW\
       echo %%F en %%F.dop are moved
       echo ------------------------
  ) else (
       echo Nothing moved
       echo ------------------------
) )  
goto :EOF

I haven made the Bash (Linux) equivalents of these scripts as well. The first script:

#!/bin/bash
for rawfile in *.ARW
do
  jpegfile="`basename "$rawfile" .ARW`.JPG"
  if [ ! -e $jpegfile ]
  then
    /bin/rm -f $rawfile
  fi
done
mkdir RAW
rm *.JPG

The 2nd script:

#!/bin/bash
for rawfile in *.ARW
do
  jpegfile="`basename "$rawfile" .ARW`_DxO.jpg"
  dopfile="$rawfile.dop"
  echo "$jpegfile"
  if [ -e $jpegfile ]
  then
    mv $rawfile ./RAW/$rawfile
    mv $dopfile ./RAW/$dopfile
  fi
done
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top