[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

File.exist? behavior problem/question

Ryan Gifford

3/21/2008 3:08:00 PM

I am getting strange behavior running the following test case:

1. Create a file on filesystem (created D:/auz.dat)
2. Check to see if the created file exists by running
File.exist?("D:/auz.dat")
3. The code returns True
4. Run File.exist?("D:/aux.dat") (this file does not exists and should
return false)
5. It returns True.

The only file that should exist is auz.dat. Looking for auu.dat or other
variations do not consistently return false and looking for aux.dat
falsely returns true every time.

File.file? seems to act the same.

I am new to Ruby and am seeing this behavior in windows (one-click
install) on any version higher than 1.8.2. On 1.8.2 it behaves as I
think it should. I am currently using 1.8.5 and cannot recreate this
behavior in linux - it seems to be specific to the windows installs I
have tried it on.

So any feedback would be appreciated - it could just be something simple
I am doing wrong. Thanks in advance.

(small test I wrote for this)
# def FileExists
fileToTest = "D:/aux.dat"
puts 'Checking for file: ' + fileToTest
if File.exist?(fileToTest)
puts 'file is there'
else
puts 'file not found'
end
# end
--
Posted via http://www.ruby-....

2 Answers

Tim Hunter

3/21/2008 5:04:00 PM

0

Ryan Gifford wrote:
> I am getting strange behavior running the following test case:
>
> 1. Create a file on filesystem (created D:/auz.dat)
> 2. Check to see if the created file exists by running
> File.exist?("D:/auz.dat")
> 3. The code returns True
> 4. Run File.exist?("D:/aux.dat") (this file does not exists and should
> return false)
> 5. It returns True.
>
> The only file that should exist is auz.dat. Looking for auu.dat or other
> variations do not consistently return false and looking for aux.dat
> falsely returns true every time.
>
> File.file? seems to act the same.
>
> I am new to Ruby and am seeing this behavior in windows (one-click
> install) on any version higher than 1.8.2. On 1.8.2 it behaves as I
> think it should. I am currently using 1.8.5 and cannot recreate this
> behavior in linux - it seems to be specific to the windows installs I
> have tried it on.
>
> So any feedback would be appreciated - it could just be something simple
> I am doing wrong. Thanks in advance.
>
> (small test I wrote for this)
> # def FileExists
> fileToTest = "D:/aux.dat"
> puts 'Checking for file: ' + fileToTest
> if File.exist?(fileToTest)
> puts 'file is there'
> else
> puts 'file not found'
> end
> # end

Well, I was waiting for somebody more experienced with Windows to chime
in, but...

This is nothing to do with Ruby. "aux" is a reserved device name in
Windows. There are others: con, prn, nul, for example. These device
names look like filenames but they always exist and they exist in every
directory. Adding an extension doesn't change anything.

Googling aux+com+dos+windows will yield a bunch of info. Here's one good
hit I found:
http://blogs.msdn.com/oldnewthing/archive/2003/10/22/....
--
Posted via http://www.ruby-....

Ryan Gifford

3/21/2008 7:32:00 PM

0

Thanks for the info. This makes sense and it was just a fluke that I was
testing for aux etc. It looks like I'm good now.

Tim Hunter wrote:
> Well, I was waiting for somebody more experienced with Windows to chime
> in, but...
>
> This is nothing to do with Ruby. "aux" is a reserved device name in
> Windows. There are others: con, prn, nul, for example. These device
> names look like filenames but they always exist and they exist in every
> directory. Adding an extension doesn't change anything.
>
> Googling aux+com+dos+windows will yield a bunch of info. Here's one good
> hit I found:
> http://blogs.msdn.com/oldnewthing/archive/2003/10/22/....
--
Posted via http://www.ruby-....