In bash there is ${files_path}/*.txt
that takes all the .txt files in the specific path. Is there an equivalent script in python?
glob
is exactly what you're looking for.
The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are returned in arbitrary order. No tilde expansion is done, but *, ?, and character ranges expressed with [] will be correctly matched.
Using glob
module:
>>> import os, glob
>>> os.listdir('.')
['package', 'test.py', 'test.pyc', 'test2.py', 'test2.pyc']
>>> glob.glob('*.pyc')
['test.pyc', 'test2.pyc']
>>>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments