Bug in ntpath.exists?

Andrew Clover esuzm at primrose.csv.warwick.ac.uk
Tue Aug 17 15:49:32 CEST 1999

This is odd.

There seems to be a problem in os.path.exists on WinNT, and presumably the
other os.stat-based calls in ntpath.

It returns true (well, 1) for objects with any number of spurious '.' and '"'
characters on the end of a filepath, and any number of spurious spaces on the
end of the filepath after these. Additionally any path element may contain a
single spurious '.' character at the end. (Also each path separator may
consist of any number of forward- or back-slashes, but that's probably

That is, if the file 'e:\fish\chips.txt' exists, the following paths are also
claimed by exists to exist:

  'e:\fish/\/\/\chips.txt....      '

and so on.

This leniency could be considered a good thing in some cases, but not in my
case since I'm writing a 404 CGI script which attempts to verify the missing
URL searched for and corrent wrong parts.

Actually open() will deal with most of these 'wrong' paths and open them
anyway, except for the case where a spurious '"' character is on the end of
a filename.

Should I fix this by bodging ntpath, or should something be changed in
os.stat, or what?

This posting was brought to you by And Clover.

More information about the Python-list mailing list