From: Tim Hunter Date: 2008-03-22T02:04:20+09:00 Subject: Re: File.exist? behavior problem/question 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/55388.aspx. -- Posted via http://www.ruby-forum.com/.