不存在的目录上的递归 glob 结果:
>>> import os, glob
>>> os.path.exists('dir')
False
>>> glob.glob('dir/*', recursive=True)
[]
>>> glob.glob('dir/**', recursive=True)
['dir/']
Run Code Online (Sandbox Code Playgroud)
现有文件的递归 glob 结果作为目录返回:
>>> os.path.exists('file')
True
>>> glob.glob('file/*', recursive=True)
[]
>>> glob.glob('file/**', recursive=True)
['file/']
Run Code Online (Sandbox Code Playgroud)
使用 bash shell 补全的类似命令将产生以下输出:
$ shopt -s globstar failglob
$ ls dir
ls: cannot access 'dir': No such file or directory
$ echo dir/*
-bash: no match: dir/*
$ echo dir/**
-bash: no match: dir/**
$ touch file
$ echo file/*
-bash: no match: file/*
$ echo file/** …Run Code Online (Sandbox Code Playgroud)