Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

search recurse sub-folders using glob.glob module python

There's a lot of confusion on this topic. Let me see if I can clarify it (Python 3.7):

glob.glob('*.txt')                  :matches all files ending in '.txt' in current directory
glob.glob('*/*.txt')                :same as 1
glob.glob('**/*.txt')               :matches all files ending in '.txt' in the immediate subdirectories only, but not in the current directory
glob.glob('*.txt',recursive=True)   :same as 1
glob.glob('*/*.txt',recursive=True) :same as 3
glob.glob('**/*.txt',recursive=True):matches all files ending in '.txt' in the current directory and in all subdirectories
So it's best to always specify recursive=True.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #search #recurse #module #python
ADD COMMENT
Topic
Name
6+1 =