How can I find all the files in a directory having the extension .txt
in python?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Python has all tools to do this:
I like os.walk():
Or with generators:
You can try this code
A simple method by using
for
loop :Though this can be made more generalised .
You can use
glob
:or simply
os.listdir
:or if you want to traverse directory, use
os.walk
:Something like this will work: