How can I list all sub directories and files using Python?
Example:
firstdir
secondir
fin.txt,testdir
How can I list all sub directories and files using Python?
Example:
firstdir
secondir
fin.txt,testdir
import os
root = "/your/path"
path = os.path.join(root, "firstdir")
for path, subdirs, files in os.walk(root):
for name in files:
print os.path.join(path, name)
Or you can directly replace your root variable in os.walk
with firstdir
Here the method walk() generates the file names in a directory tree by walking the tree either top-down or bottom-up.