Forum: Ruby Problem with File.exists? giving an incorrect result

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D29c53311c32eb408aaba2e5ae55d161?d=identicon&s=25 Chris Dwan (Guest)
on 2007-07-22 12:22
(Received via mailing list)
I have a problem with a script I'm working on.  File.exists? is
telling me that a file does in fact exist, then immediately after
when I try to do a, it crashes because the file doesn't
exist.  I know that it does not exist, because I'm testing that
condition. If the file doesn't exist, it should do something else.

<sigh> this is on Windows, so maybe the OS is to blame?
Here's the code, if it helps..

             $debug_log.fatal("does file exist? :: #{ibl}")
             if File.exist?(ibl)
               $debug_log.fatal("YES - it most certainlyt does!")
               iblLocation = ibl
                 #find the file and set iblLocation
    # << bombs here

The file referred to by ibl was recently renamed by this same script,
so the file name in ibl is no longer valid. The script should then go
looking for ibl's new name and use that... but it won't work <sob><sob>

Hope someone can enlighten me.
D86ec78a7a258246684d15e09e51a170?d=identicon&s=25 Sharon Phillips (Guest)
on 2007-07-22 12:41
(Received via mailing list)
On 22/07/2007, at 8:21 PM, Chris Dwan wrote:

>             if File.exist?(ibl)
> won't work <sob><sob>
> Hope someone can enlighten me.
> Thanks!

I assume you have permission to read the file?
1c0cd550766a3ee3e4a9c495926e4603?d=identicon&s=25 John Joyce (Guest)
on 2007-07-22 16:48
(Received via mailing list)
On Jul 22, 2007, at 5:21 AM, Chris Dwan wrote:

>             if File.exist?(ibl)
> won't work <sob><sob>
> Hope someone can enlighten me.
> Thanks!
You need to open the file  first.  OR
check them with ri first, you may need to choose binary or text when
setting the file mode because you're using windows
05e48e632fdd0b2c25d27042f52c11d5?d=identicon&s=25 Alex LeDonne (Guest)
on 2007-07-23 03:12
(Received via mailing list)
On 7/22/07, Chris Dwan <> wrote:
>              if File.exist?(ibl)
> Hope someone can enlighten me.
> Thanks!
What does the rename code look like? I've seen lots of weirdness on
Windows because file operations that you might think are atomic,

F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (Guest)
on 2007-07-23 03:57
(Received via mailing list)

At Sun, 22 Jul 2007 19:21:19 +0900,
Chris Dwan wrote in [ruby-talk:261241]:
>     # << bombs here
What are the actual exception you get, and the version?  And
$debug_log shows "YES - ..."?
This topic is locked and can not be replied to.