From c98b26a6ac0e5e68dd2eb820430cc2a44b4df019 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 7 Sep 2016 09:49:42 +0300 Subject: Issue #25596: Falls back to listdir in glob for bytes paths on Windows. --- Lib/glob.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py index 002cd92..7c3cccb 100644 --- a/Lib/glob.py +++ b/Lib/glob.py @@ -118,13 +118,22 @@ def _iterdir(dirname, dironly): else: dirname = os.curdir try: - with os.scandir(dirname) as it: - for entry in it: - try: - if not dironly or entry.is_dir(): - yield entry.name - except OSError: - pass + if os.name == 'nt' and isinstance(dirname, bytes): + names = os.listdir(dirname) + if dironly: + for name in names: + if os.path.isdir(os.path.join(dirname, name)): + yield name + else: + yield from names + else: + with os.scandir(dirname) as it: + for entry in it: + try: + if not dironly or entry.is_dir(): + yield entry.name + except OSError: + pass except OSError: return -- cgit v0.12