To traverse every file and directory in a directory tree you can use the following piece of code:-
import os for dirname, dirnames, filenames in os.walk('.'):
for subdirname in dirnames:
for filename in filenames:
Another way by which you can list all the Directory trees in Python is by using the following piece of code:-
If you are looking for upskilling yourself in python you can join our Python Certification and learn from the industrial expert!