Strange os.path.exists() behaviour

Jeff Epler jepler at
Wed Jul 6 22:07:23 CEST 2005

Pierre wrote:
> Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Here's the bug.  You're using Windows.  It's a filesystem, but not as we know it...

Anyway, You are getting exactly what the low-level Windows APIs return.

Here's a small "C" program.  It prints "0" next to the filename if the
file exists, -1 otherwise, as described at

int main(int argc, char **argv) {
    int i;
    for(i=1; i<argc; i++) {
        printf("%20s: %d\n", argv[i], _access(argv[i], 0)); 

I compiled it with "i386-mingw32msvc-gcc -o a.exe exist.c"

Here's an example session with it:
     Volume in drive C has no label.
     Volume Serial Number is 171D-4D2A

     Directory of C:\TMP\example

    07/06/05  03:04p        <DIR>          .
    07/06/05  03:04p        <DIR>          ..
    07/06/05  03:05p                     3 exist
                   3 File(s)              3 bytes

    C:\TMP\example>x:a.exe exist exist. exist.... nonexist nonexist. nonexist...
                   exist: 0
                  exist.: 0
               exist....: 0
                nonexist: -1
               nonexist.: -1
             nonexist...: -1

    C:\TMP\example>type nonexist....
    The system cannot find the file specified.

    C:\TMP\example>type exist....


As you can see, not only does Windows think that "exist...." exists, but it can
successfully "type" its contents too!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list