Why exception from os.path.exists()?

eryk sun eryksun at gmail.com
Fri Jun 1 20:48:17 EDT 2018


On Sat, Jun 2, 2018 at 12:14 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>
> It isn't even a set of minimum requirements. "<" is legal under POSIX,
> but not Windows.

"<" (i.e. the DOS_STAR wildcard character) is valid in device and
stream names. It's only invalid in filenames, since it's reserved for
wildcard matching in file-system calls.

For example, in the following we have a device named
'<DEVICENAME|"*?/>:' (note the name contains a forward slash) and a
stream named '<STREAMNAME|"*?>'. The stream component requires NTFS,
ReFS, or CDFS; FAT doesn't support it. Stream names also allow ASCII
control characters, except NUL.

    >>> DefineDosDevice(0, '<DEVICENAME|"*?/>:', 'C:\\Temp')
    >>> f = open(r'\\?\<DEVICENAME|"*?/>:\FILENAME.TXT:<STREAMNAME|"*?>', 'w')
    >>> os.path.exists(r'\\?\<DEVICENAME|"*?/>:\FILENAME.TXT:<STREAMNAME|"*?>')
    True



More information about the Python-list mailing list