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.
misiek (Guest)
on 2006-03-06 20: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
ChrisH (Guest)
on 2006-03-06 23: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
Robert K. (Guest)
on 2006-03-06 23:57
(Received via mailing list)
2006/3/6, misiek <removed_email_address@domain.invalid>:
>
>
> 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.