Eryk Sun <[email protected]> added the comment:
> On Windows the extension of "python.exe" is "exe", not ".exe".
FWIW, a file extension in Windows includes the dot. Trailing dots are stripped
from filenames, so a file can't be named "python." because it's the same as
just "python". (It's possible to prevent stripping trailing dots from a name by
using a \\?\ literal path, but creating such a filename is a bad idea.)
The shell API's file associations include the dot in the file extension. Also,
the PATHEXT environment variable (i.e. the list of extensions that a CLI shell
should try appending in a PATH search) includes the dot in each extension. In
both of the latter cases, an extension that's just "." matches a filename that
has no extension. In other words, the "." file extension can be used to
associate files that have no extension with a ProgID (i.e. a programmatic
identifier, which defines properties and actions for a file type), and adding
"." to PATHEXT includes files that have no extension in a PATH search.
To clarify further, here are some results from PathCchFindExtension() [1]:
import ctypes
path = ctypes.OleDLL('api-ms-win-core-path-l1-1-0')
s = (ctypes.c_wchar * 100)()
ext = ctypes.c_wchar_p()
>>> s.value = 'python.exe'
>>> _ = path.PathCchFindExtension(s, len(s), ctypes.byref(ext))
>>> ext.value
'.exe'
>>> s.value = '...exe'
>>> _ = path.PathCchFindExtension(s, len(s), ctypes.byref(ext))
>>> ext.value
'.exe'
>>> s.value = 'python.'
>>> _ = path.PathCchFindExtension(s, len(s), ctypes.byref(ext))
>>> ext.value
'.'
---
[1]
https://docs.microsoft.com/en-us/windows/win32/api/pathcch/nf-pathcch-pathcchfindextension
----------
nosy: +eryksun
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34931>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com