[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

if File.exist? does not work

misiek

3/6/2006 6:41:00 PM

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
2 Answers

Chris Hulan

3/6/2006 9:09:00 PM

0

misiek wrote:
> 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

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 Klemme

3/6/2006 9:57:00 PM

0

2006/3/6, misiek <michaelaugustyniak@gazeta.pl>:
> 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

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


--
Have a look: http://www.flickr.com/photos/fu...