I have a folder in Windows 7 which contains multiple .txt
files. How would one get every file in said directory as a list?
相关问题
- 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
If you just need the current directory, use os.listdir.
You can also use os.walk if you need to recursively get the contents of a directory. Refer to the python documentation for os.walk.
You can use
os.listdir(".")
to list the contents of the current directory ("."):If you want the whole list as a Python list, use a list comprehension:
All of the answers here don't address the fact that if you pass
glob.glob()
a Windows path (for example,C:\okay\what\i_guess\
), it does not run as expected. Instead, you need to usepathlib
: