Files and variables (noob alert)

J

John Maclean

Chaps,

Say you've defined a variable:-

a = "l2.txt" # where l2.txt is a file that you know exists
irb(main):009:0> File.exist?("l2.txt")
=> true

#How can I use the variable a within the File.exist(parameter)?
irb(main):012:0> a
=> "l2.xt"

irb(main):013:0> File.exist?(a)
=> false

irb(main):015:0> File.exist?("#@a")
=> false
 
W

Wilson Bilkovich

Chaps,

Say you've defined a variable:-

a =3D "l2.txt" # where l2.txt is a file that you know exists
irb(main):009:0> File.exist?("l2.txt")
=3D> true

#How can I use the variable a within the File.exist(parameter)?
irb(main):012:0> a
=3D> "l2.xt"

irb(main):013:0> File.exist?(a)
=3D> false

irb(main):015:0> File.exist?("#@a")
=3D> false

That should just work:

irb(main):010:0> File.exist? 'helloworld.rb'
=3D> true
irb(main):011:0> a =3D 'helloworld.rb'
=3D> "helloworld.rb"
irb(main):012:0> File.exist? a
=3D> true
irb(main):013:0> File.exist? 'nothere'
=3D> false
 
J

John Maclean

Thanks!
That should just work:

irb(main):010:0> File.exist? 'helloworld.rb'
=> true
irb(main):011:0> a = 'helloworld.rb'
=> "helloworld.rb"
irb(main):012:0> File.exist? a
=> true
irb(main):013:0> File.exist? 'nothere'
=> false
 
J

John Maclean

irb(main):006:0> x = 'l2.txt' if File.exist? 'l2.txt'
=> "l2.txt"
irb(main):007:0> x
=> "l2.txt"

Thanks ever so much for your speedy reply. Now I'm starting to get
somewhere!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top