- Mastering Python for Networking and Security
- José Manuel Ortega
- 61字
- 2021-07-16 17:40:00
Recursing through directories
In some cases, it is necessary to iterate recursively through the main directory to discover new directories. In this example, we see how we can browse a directory recursively and retrieve the names of all files within that directory:
import os
# you can change the "/" to a directory of your choice
for file in os.walk("/"):
print(file)