I am facing difficulty in getting the xml structure listing all the directories/ sub directories inside a given directory. I got that working using the recursion in the given post My problem is little bit tougher than usual. I have directories that may have 10000 of files in it so checking every content to see if its a directory or not is going to be costly and its already taking to long to build the xml. I want to build the xml for directories only.
I know linux has some command like find . -type d to list the directories present (not the files). How can I achieve this in python.
Thanks in advance.
os.walk
already distinguishes between files and directories:
def find_all_dirs(root='.'):
for path,dirs,files in os.walk(root):
for d in dirs:
yield os.path.join(path, d)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With