Why do I get "Errno::ENOENT: No such file or directory" when joining a filename?

StackOverflow https://stackoverflow.com/questions/18131637

  •  24-06-2022
  •  | 
  •  

سؤال

I have a file I'm trying to open in a Rails application. For some reason Ruby is splitting the name of the file.

For example:

root = Rails.root
path = root.join('lib/tasks/filename.shp')
puts path

What is output is /lib/tasks/filename/shp.

Then I run the command:

factory = Region::GEOFACTORY
RGeo::Shapefile::Reader.open(path, :factory => factory) do |file|

I get the error message:

Errno::ENOENT: No such file or directory - /lib/tasks/filename/.shp

It looks like the file has been split into filename and .shp?

هل كانت مفيدة؟

المحلول

Try

path = File.join(Rails.root, 'lib/tasks/filename.shp')
factory = Region::GEOFACTORY
RGeo::Shapefile::Reader.open(path, :factory => factory)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top