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.

Author jimbo1qaz_
Recipients jimbo1qaz_
Date 2018-11-24.05:55:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1543038959.25.0.788709270274.issue35306@psf.upfronthosting.co.za>
In-reply-to
Content
I'm writing a program taking paths from user input through CLI.

`path` is a pathlib.Path().

Since Windows doesn't expand asterisks, I check if the path doesn't exist. If so I expand using Path().glob(path).

Unfortunately on Windows, if `path` (type: Path) contains asterisks, checking `path.exists()` or `path.is_dir()` raises WinError 123.

Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('*').exists()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1318, in exists
    self.stat()
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1140, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '*'
>>> Path('*').is_dir()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1330, in is_dir
    return S_ISDIR(self.stat().st_mode)
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1140, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '*'

I also reproduced on Miniconda 3.6.6, 3.7.0, and official Python 3.7.1.

According to https://bugs.python.org/issue29827 , os.path.exists() (not Path.exists() ) returns False on any OSError.

-----------------

On Linux, checking paths with null bytes (a less common occurrence) raises a different error:

>>> import pathlib
>>> pathlib.Path("\x00").exists()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/pathlib.py", line 1336, in exists
    self.stat()
  File "/usr/lib/python3.6/pathlib.py", line 1158, in stat
    return self._accessor.stat(self)
  File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
ValueError: embedded null byte
History
Date User Action Args
2018-11-24 05:55:59jimbo1qaz_setrecipients: + jimbo1qaz_
2018-11-24 05:55:59jimbo1qaz_setmessageid: <1543038959.25.0.788709270274.issue35306@psf.upfronthosting.co.za>
2018-11-24 05:55:59jimbo1qaz_linkissue35306 messages
2018-11-24 05:55:58jimbo1qaz_create