环境:OSX10.10/Ruby9.6/ iPhoto 2.2
在ruby脚本中,我试图打开'iPhoto库‘中的一个xml文件来获取专辑列表。但是我得到了一个错误:
f = File.open(@xmlpath)
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/myself/Pictures/iPhoto%20Library/AlbumData.xml首先,我在我的用户路径中定义了'iPhoto库‘路径:
PhotoLib = File.expand_path(File.join("~","Pictures","iPhoto Library")然后我定义了@xml文件路径(转义嵌入的空格)
@xmlpath = URI.escape(File.join iPhotoLib, "AlbumData.xml")最后,我尝试打开xml文件
f = File.open(@xmlpath)但它会引发“No No file or directory”错误...我哪里错了?该文件存在于"iPhoto库“内容中...
发布于 2015-03-20 21:26:52
您不应该使用URI.escape -这是针对url的,但是您传递给File.open的是本地文件系统上的路径,而不是url。特别是百分比转义("%20")对您的文件系统没有意义
发布于 2015-03-20 21:45:03
我应该使用
library_path = Pathname.new(ENV"HOME") +“图片”+ "iPhoto Library.photolibrary“xml_path = library_path + "AlbumData.xml”f= File.open(xml_path)
路径名正确处理它....
https://stackoverflow.com/questions/29167250
复制相似问题