Hi,
still a noob, and still hacking a script to traverse photo directories
to populate a mysql db with various photo metadata. nearly there, but
having trouble handling an error from DateTime that dies on a file that
doesn't have 3 elements of a civil date.
can anyone recommend a way of handling this error so that the loop skips
to the next iteration?
code below.
many thanks in advance
···
===
....
find.find(directory) do |path|
next if File.directory?(path)
next unless path =~ /.jpg$/ or /.JPG$/
puts "trying picture: #{path} "
# get metadata
pathName = path
baseName = File.basename(path)
fileSize = File.size(path)
cameraModel = EXIFR::JPEG.new(path).exif.model
picWidth = EXIFR::JPEG.new(path).width
picHeight = EXIFR::JPEG.new(path).height
picDateTaken = EXIFR::JPEG.new(path).date_time_original
DateTime.parse("#{picDateTaken}")
^^^error point
mysqlDate = DateTime.parse("#{picDateTaken}")
picShutterSpeed = EXIFR::JPEG.new(path).exposure_time
picAperture = EXIFR::JPEG.new(path).fnumber #returns a fraction as
string
aperture = picAperture.to_f
focalLength = EXIFR::JPEG.new(path).focal_length
num+= 1
# => PRINT
puts "added picture: #{pathName} total pics:#{num}"
db.query("INSERT INTO JPGS (name, path, size, model, width, height,
timeStamp, shutterSpeed, aperture, focalLength)
VALUES ('#{baseName}', '#{pathName}', '#{fileSize}', '#{cameraModel}',
'#{picWidth}', '#{picHeight}', '#{mysqlDate}', '#{picShutterSpeed}',
'#{aperture}','#{focalLength}') ")
end
--
Posted via http://www.ruby-forum.com/.