[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

handle ArgumentError to resume loop at next iteration

jay

2/22/2007 4:43:00 PM

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-....

1 Answer

Austin Ziegler

2/22/2007 5:18:00 PM

0

On 2/22/07, jay <jay.johnston@gmail.com> wrote:
[...]
begin
DateTime.parse(picDateTaken)
rescue ArgumentError
next
end
[...]

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca