diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -56,8 +56,11 @@ # `os.path.split()` returns the argument itself as a dirname if it is a # drive or UNC path. Prevent an infinite recursion if a drive or UNC path # contains magic characters (i.e. r'\\?\C:'). - if dirname != pathname and has_magic(dirname): - dirs = _iglob(dirname, recursive) + if not has_magic(dirname) and not os.path.isdir(dirname): + return + elif dirname != pathname and has_magic(dirname): + dirs = (d for d in _iglob(dirname, recursive) if + not d or os.path.isdir(d)) else: dirs = [dirname] if has_magic(basename): @@ -115,6 +118,8 @@ dirname = bytes(os.curdir, 'ASCII') else: dirname = os.curdir + assert os.path.isdir(dirname) + try: names = os.listdir(dirname) except os.error: @@ -123,8 +128,9 @@ if not _ishidden(x): yield x path = os.path.join(dirname, x) if dirname else x - for y in _rlistdir(path): - yield os.path.join(x, y) + if os.path.isdir(path): + for y in _rlistdir(path): + yield os.path.join(x, y) magic_check = re.compile('([*?[])')