Result would look like something like this: Echo selected with path: /Volumes/photo/DNG/2015 That would echo all filenames of jpg files that match the criteria of having both dng and jpg file with same name. m: for move (moves files to /duplicates)īasic usage would work like this: $.
Here's how to use the script: Usage: dng-jpg.sh Those are inevitable casualties of this script. Warning: You could have two different images with same name, but different extension. It will go through subfolders, so you could use it for your entire catalog or just parts of it.įor other raw file extensions just substitute *.dng in the script with your preferred extension. If a jpg is found with an exactly same name as dng, then that filename is displayed ( -e), file is moved ( -m) or deleted ( -d). It looks for files that exist with same base filename and dng+jpg extensions. A lot of good ideas came from earlier scripts mentioned here. Mv "$filepath/$prefix.$rsuffix" "$filepath/$WASTEDIR"Įcho "Removing duplicate $filepath/$prefix.$rsuffix" If thenĮcho "Moving $filepath/$prefix.$rsuffix to $filepath/$WASTEDIR" If ]] then rsuffix="JPG" else rsuffix="jpg" fi įind "$BASEDIR" -iname '*.dng' -print0 | while read -d $'\0' filename I like to see what's going on, especially when mv or rm commands are used )įor the sake of the space I am showing only the last part of the script, from setting a basedir, wastedir and the loop. You define a name of the directory before the loop. The original solution proposed only one wastedir location, whereas my fix allows a subdirectory to be created on each directory branch as it travels though. Note, that it only accepts DNG+JPG or dng+jpg pairs, and it will ignore any combinations such as DNG+jpg or DnG+JpG. I have slightly improved that part of the script to account for extensions that are in uppercase as well. The original script only works for lowercase extensions. That required a bit different handling of the find command. It did not like my directory names, which contain spaces. I like the bash script for OS X (by T.Toivonen), but I have noticed there are a few issues. Print "%s: %s = %s => %s" % (path, base_name, jpg, waste_dir) New_jpg = waste_dir + jpg_base_name_with_ext Jpg_base_name_with_ext = base_name + jpg_extension # find pairs and move jpgs of pairs to waste basket Jpg_ext = (jpg_extension.lower(), jpg_extension.upper())įor path, dirs, files in os.walk(os.path.abspath(root)):īase_name = os.path.splitext(base_name) Raw_ext = tuple(map(str.lower,raw_extensions)) + tuple(map(str.upper,raw_extensions)) '''Locate files in directory with given extensions''' Waste_dir = "/Users/marvin/Pictures/waste/"
# Windows : waste_dir = "C:\path\to\waste\"
# multiple raw extensions allowed, single jpg extension only # define your file extensions here, case is ignored. # For each pair found the JPG is moved to a # Description: This script looks in all sub directories for