I'm trying to do a File.exist?(file)
but my ruby script开发者_如何学编程 doesn't find the file because of \, spaces, - and . in the filepath. I'm a beginner in ruby and need some help to fix this.
I assume it has to do with your OS, more then with Ruby.
file tèst.rb:
puts "Hello"
puts "smørebrød"
used in irb:
irb(main):001:0> require "tèst.rb"
Hello
smørebrød
Ruby can include a file with name tèst.rb just fine.
irb(main):005:0> f = File.new("ÅÄÖ.txt")
irb(main):006:0> f.each {|l| p l }
"\"Hej Verden\"\n"
loading a file with your requested characters and printing its lines (p l
) works just fine.
I am running ruby 1.8.7
on Ubuntu Linux
. That is a rather old Ruby.
精彩评论