Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No such file or directory - ruby

Tags:

ruby

I am trying to read the contents of the file from a local disk as follows :

content = File.read("C:\abc.rb","r")

when I execute the rb file I get an exception as Error: No such file or directory .What am I missing in this?

like image 489
user1400915 Avatar asked Nov 18 '25 15:11

user1400915


2 Answers

In a double quoted string, "\a" is a non-printable bel character. Similar to how "\n" is a newline. (I think these originate from C)

You don't have a file with name "C:<BEL>bc.rb" which is why you get the error.

To fix, use single quotes, where these interpolations don't happen:

content = File.read('C:\abc.rb')
like image 195
Tim Peters Avatar answered Nov 20 '25 16:11

Tim Peters


content = File.read("C:\/abc.rb","r")
like image 29
jainvikram444 Avatar answered Nov 20 '25 18:11

jainvikram444



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!