0

env: OSX 10.10 / iPhoto 9.6 / Ruby 2.2

in a ruby script, I am trying to open an xml file from the 'iPhoto Library' to get the album list.. but I got an error :

 f = File.open(@xmlpath)
 Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/myself/Pictures/iPhoto%20Library/AlbumData.xml

first, I defined the 'iPhoto Library' path in my user path :

PhotoLib = File.expand_path(File.join("~","Pictures","iPhoto Library")

then I defined the @xml file path ( escaping the embedded spaces )

 @xmlpath = URI.escape(File.join iPhotoLib, "AlbumData.xml")

finally I try to open the xml file

 f = File.open(@xmlpath)

but it raises the 'No such file or directory' error... where am I wrong ? the file exists in the "iPhoto Library" content ...

2 Answers2

0

You shouldn't be using URI.escape - that is for urls but what you pass to File.open is a path on your local filesystem, not a url. In particular percentage escapes ("%20") don't make sense to your filesystem

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • ok, you're right ...however I found my error .. I should use Pathname.new : library_path = Pathname.new(ENV["HOME"]) + "Pictures" + "iPhoto Library.photolibrary" , then the path would be correct ... –  Mar 20 '15 at 13:42
0

I should use

library_path = Pathname.new(ENV["HOME"]) + "Pictures" + "iPhoto Library.photolibrary" xml_path = library_path + "AlbumData.xml" f = File.open(xml_path)

Pathname handle correctly it ....