Search
 
SCRIPT & CODE EXAMPLE
 

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.
Comment

PREVIOUS NEXT
Code Example
Python :: TemplateDoesNotExist at / 
Python :: Python NumPy repeat Function Example Working with 1D array 
Python :: Python NumPy vsplit Function Syntax 
Python :: python os.listdir attributes 
Python :: mid-point line drawing 
Python :: retinaface detection 
Python :: __sub__ 
Python :: Python how to use __ne__ 
Python :: NumPy fliplr Example 
Python :: selenium rotate user agent 
Python :: how to increment date in python 
Python :: NumPy right_shift Code When inputs and bit shift are an arrays 
Python :: django view - apiview decorator (urls.py config) 
Python :: selenium python select elements data atribute 
Python :: python restrict function parameter type 
Python :: how to avoind DeprecationWarning in python 
Python :: numpy extract decimal 
Python :: beautifulsoup - extracting link, text, and title within child div 
Python :: qmenu 
Python :: how to make a half pyramid in python 
Python :: Example 1: How isidentifier() works? 
Python :: How do I pre-select specific values from a dynamically populated dropdown list for HTML form 
Python :: python socket backlog 
Python :: python json string indices must be integersAdd Answer 
Python :: ring Delete Item From List 
Python :: can you make a class in a class python 
Python :: how to dynamically append value in a list in python 
Python :: python loc id in list 
Python :: unable to access jupiter assertions 
Python :: ax text relative coordinates 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =