Forum: Ruby if File.exist? does not work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9aa1e92a0ebb17fdaad2fa39b4c52b8a?d=identicon&s=25 misiek (Guest)
on 2006-03-06 19:44
(Received via mailing list)
I got like:


if File.exist?
"#{RAILS_ROOT}/public/images/#{property.id}/middle/#{image.name}"
File.unlink
"#{RAILS_ROOT}/public/images/#{property.id}/middle/#{image.name}"
end

why it does not work ?


error
No such file or directory -
script/../config/../public/images/144/middle/cfa9a31932bea2904485b56294764a6b.jpg
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 ChrisH (Guest)
on 2006-03-06 22:14
(Received via mailing list)
misiek wrote:
>
>
> error
> No such file or directory -
> script/../config/../public/images/144/middle/cfa9a31932bea2904485b56294764a6b.jpg

The snippet you posted works, assuming the wrapping is introduced by
the post software.

Could there be a typo that is causing the 'if' to be treated as the end
of a previous statement?  This would also require a 'begin' to match
the 'end'...

cheers
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2006-03-06 22:57
(Received via mailing list)
2006/3/6, misiek <michaelaugustyniak@gazeta.pl>:
>
>
> error
> No such file or directory -
> script/../config/../public/images/144/middle/cfa9a31932bea2904485b56294764a6b.jpg

Looks ok to me.  But to avoid spelling errors I'd store the name in a
variable like
f = File.join RAILS_ROOT, "public", "images", property.id, "middle",
image.name
File.unlink f if File.exists? f

HTH

Kind regards

robert
This topic is locked and can not be replied to.