From: Joda jenson Date: 2011-09-29T18:14:24+09:00 Subject: IO.readlines will not accept variable with file name Why? I am fairly new to Ruby and I am stuck on this. Would someone have a suggestion. I'm trying to read a file with IO.readlines, letting a user give the file name. __________________________________________________ puts "what is the name of the file=>" filename1 = gets filearray = IO.readlines(filename) puts filearray [0] __________________________________________________ If I hard code the file name works great. filearray = IO.readlines("/home/user/file.txt") __________________________________________________ It seems to be something to do with the double quotes. I have tried to wrap the variable with double quotes. filename1 = ("\"/home/user/file.txt\"") It will print the Double quote but still will not work if I pass it to the IO.readlines() It gives a (Errno::ENOENT) It doesn't seem to matter how I doctor a string with quotes I can't get IO.readlines() to accept it. Only hard coding it works for some reason. Thanks for any help. -- Posted via http://www.ruby-forum.com/.