using "NOT" in File.exists?

P

Peter Bailey

Hello,
I want to create a boolean variable for a "not" statement. When I do a
"not File.exists?" in IRB, it works fine. But, it doesn't work when it's
part of a variable declaration. Can someone help me to create a truth
variable for a statement like this?

Thanks,
Peter

doesn't work in script. . . .
pngthere = not File.exists?("L:/png/#{pngdir}/#{pngfile}")

in IRB. . . .
not File.exists?("L:/png/#{pngdir}/#{pngfile}")
works fine.
 
A

Alex Young

Peter said:
Hello,
I want to create a boolean variable for a "not" statement. When I do a
"not File.exists?" in IRB, it works fine. But, it doesn't work when it's
part of a variable declaration. Can someone help me to create a truth
variable for a statement like this?

Thanks,
Peter

doesn't work in script. . . .
pngthere = not File.exists?("L:/png/#{pngdir}/#{pngfile}")

in IRB. . . .
not File.exists?("L:/png/#{pngdir}/#{pngfile}")
works fine.
Try:

pngthere = !File.exists?("L:/png/#{pngdir}/#{pngfile}")
 
A

Arie Kusuma Atmaja

Hello,
I want to create a boolean variable for a "not" statement. When I do a
"not File.exists?" in IRB, it works fine. But, it doesn't work when it's
part of a variable declaration. Can someone help me to create a truth
variable for a statement like this?

Thanks,
Peter

doesn't work in script. . . .
pngthere = not File.exists?("L:/png/#{pngdir}/#{pngfile}")

in IRB. . . .
not File.exists?("L:/png/#{pngdir}/#{pngfile}")
works fine.

sayang:~/2 arie$ irb
Arigatou jyanai! Pizza wa (2) ni-mai, OK!
Terima kasih boleh2 saja, pizza+hotel_empuk itulah yg lebih dari boleh2 saja
irb(main):001:0> File.exists?('1.tcl')
=> true
irb(main):002:0> !File.exists?('1.tcl')
=> false
irb(main):003:0> "a" unless File.exists?('1.tcl')
=> nil
irb(main):004:0> puts "a" unless File.exists?('1.tcl')
=> nil
irb(main):005:0> puts "a" if File.exists?('1.tcl')
a
=> nil
irb(main):006:0> tclthere = !File.exists?('1.tcl')
=> false
irb(main):007:0> tclthere2 = not File.exists?('1.tcl')
SyntaxError: compile error
(irb):7: syntax error, unexpected kNOT
tclthere2 = not File.exists?('1.tcl')
^
from (irb):7
from :0
irb(main):008:0>
 
A

Arie Kusuma Atmaja

doesn't work in script. . . .
pngthere = not File.exists?("L:/png/#{pngdir}/#{pngfile}")

pngthere = (not File.exist?('pngfile'))

sayang:~/2 arie$ touch pngfile
sayang:~/2 arie$ irb
irb(main):001:0> pngthere = (not File.exist?('pngfile'))
=> false
irb(main):002:0>
 

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,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top