This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Strange os.path.exists() results with invalid chars
Type: Stage:
Components: Windows Versions: Python 2.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: dvarrazzo, georg.brandl, grubert, zgoda
Priority: normal Keywords:

Created on 2005-04-30 23:13 by dvarrazzo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg25196 - (view) Author: Daniele Varrazzo (dvarrazzo) * Date: 2005-04-30 23:13
Hi,

when there are invalid chars in a filename, os.path.exists
() behaves oddly, returning True.

The bug appears on win32 system, not on unix ones. 
Thus is probably related to some weird windows api call 
and doesn't maybe worth fixing.

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import os
>>> f = file("a_b", "w")
>>> f.close()
>>> os.listdir(".")
['a_b']
>>> os.path.exists("a<b")
True
>>> os.path.exists("a>b")
True

And, even more strange...

>>> os.path.exists("a<")
True
>>> os.path.exists("a>")
False

Better answers would have been:
  * False
  * raise ValueError
msg25197 - (view) Author: Jarek Zgoda (zgoda) Date: 2005-05-02 12:04
Logged In: YES 
user_id=92222

Same for Python 2.3.5.
msg25198 - (view) Author: engelbert gruber (grubert) * Date: 2005-05-23 06:52
Logged In: YES 
user_id=147070

testing with perl: print -e "a<"; returns True/1 too
msg25199 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-05-31 09:56
Logged In: YES 
user_id=1188172

I think Python just uses the Win32 system call, so there
isn't much Python can do about it.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 41932
2005-04-30 23:13:21dvarrazzocreate