[Digikam-users] Thank you!
Guy Stalnaker
jimmyg521 at gmail.com
Fri Mar 9 01:09:02 GMT 2012
John asked about the two tools I used for my image collection
restore/rename. One was digikam of course. The other is a commandline
shell script that uses exif_tool:
http://www.sno.phy.queensu.ca/~phil/exiftool/
It's available for Win/Mac/*Nix. I'm using Linux (kubuntu 11.10) and the
script below is what uses exif_tool and a bit of *nix magic. The gist of
it is using output from exif_tool
exiftool -S -d "%Y/%m/%d/DSCN_%Y%m %dT%H%M%S" -EXIF:DateTimeOriginal $file
parsed through awk
awk '{print $2}
to isolate just the date/time output, which is then added to a string to
form a filename path:
$HOME/Pictures/<awk_output>
which is assigned to a variable DEST.
That variable is the new path/filename. The install command is what
actually renames the input file and does the move. If a file already
exists with the name, the install command will not overwrite the
existing file, but will append ~#~ to the end fo the file being moved,
with # replaced the a real number.
The shell script is very basic and could with a bit of work be more
elegant but it is functional and at present I'd rather just use it and
futz with it. If you're familiar with using commandline tools like this
in the Linux world just copy between the <quote></quote> to a file, set
the file executable (chmod +x <filename>), and put it where it can be
found (somewhere in the PATH env variable paths, e.g., /usr/local/bin).
You can remove the # before set -x and the script will output what it's
doing as it does it):
<quote>
#!/bin/bash
# copy image files in and below the current(!) directory to
# ~/Pictures/YEAR/MONTH/DAY/DSCN_YYYYMMDDTHHMMSS.jpg
#
# requires exiftool (pacman -S perl-exiftool)
#
# Designate filetype on command line:
# %> exif_rename.pl jpg|JPG|gif|GIF|png|PNG|tif|TIF|nrw|NRW|nef|NEF
#set -x
args=("$@")
FILETYPE=${args[0]}
if [[ $FILETYPE = "jpg" || $FILETYPE = "JPG" ]] ; then
for file in *.jpg *.JPG; do
dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/DSCN_%Y%m \
%dT%H%M%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').jpg"
echo "$file -> $dest"
install --backup=numbered -v -D -m 644 "$file" "$dest" && rm -rf
"$file"
done
elif [[ $FILETYPE = "gif" || $FILETYPE = "GIF" ]] ; then
for file in *.gif *.GIF; do
dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/DSCN__%Y%m \
%dT%H%M%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').gif"
echo "$file -> $dest"
install --backup=numbered -v -D -m 644 "$file" "$dest" && rm -rf
"$file"
done
elif [[ $FILETYPE = "png" || $FILETYPE = "png" ]] ; then
for file in *.png *.PNG; do
dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/DSCN_%Y%m \
%dT%H%M%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').png"
echo "$file -> $dest"
install --backup=numbered -v -D -m 644 "$file" "$dest" && rm -rf
"$file"
done
elif [[ $FILETYPE = "tif" || $FILETYPE = "TIF" ]] ; then
for file in *.tif *.TIF; do
dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/DSCN_%Y%m \
%dT%H%M%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').tif"
echo "$file -> $dest"
install --backup=numbered -v -D -m 644 "$file" "$dest" && rm -rf
"$file"
done
elif [[ $FILETYPE = "nrw" || $FILETYPE = "NRW" ]] ; then
for file in *.nrw *.NRW; do
dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/DSCN_%Y%m \
%dT%H%M%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').nrw"
echo "$file -> $dest"
install --backup=numbered -v -D -m 644 "$file" "$dest" && rm -rf
"$file"
done
elif [[ $FILETYPE = "nef" || $FILETYPE = "NEF" ]] ; then
for file in *.nef *.NEF; do
dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/DSCN_%Y%m \
%dT%H%M%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').nef"
echo "$file -> $dest"
install --backup=numbered -v -D -m 644 "$file" "$dest" && rm -rf
"$file"
done
else
echo "No image files found."
fi%
</quote>
On 03/07/2012 03:05 AM, John Bestevaar wrote:
> Hi Guy
> Would you let us know the names of the two tools you used?
> Your scenario is one at least some of us may also encounter.
> Cheers John Bestevaar
>
> On 07/03/12 16:13, Guy Stalnaker wrote:
>> *nix magic
> _______________________________________________
> Digikam-users mailing list
> Digikam-users at kde.org
> https://mail.kde.org/mailman/listinfo/digikam-users
--
"There is only love, and then oblivion. Love is all we have
to set against hatred." (paraphrased) Ian McEwan
Guy Stalnaker
jimmyg521 at gmail.com
More information about the Digikam-users
mailing list