How can we write code in Python to find all file system including files from root to each and every file of the current computer system.
How can we write code in Python to find all file system including files from root to each and every file of the current computer system.
You can use the os.walk
method. Here is an example:
# !/usr/bin/pythonimport os
for root, dirs, files in os.walk(".", topdown=False):for name in files:print(os.path.join(root, name))for name in dirs:print(os.path.join(root, name))
copied from http://www.tutorialspoint.com/python/os_walk.htm
See the full documentation: https://docs.python.org/2/library/os.html#os.walk