Python os.walk() get files before directories - TagMerge
1Python os.walk() get files before directoriesPython os.walk() get files before directories

Python os.walk() get files before directories

Asked 11 months ago
1
1 answers

You can use files or dirs like this:

import os
root_path = r'/home/testuser/test/'
for root, dirs, files in os.walk(root_path, topdown=True):
    print(root)
    print(dirs)
    print(files)

also you can walk through directories from bottom to top with topdown=False

Source: link

Recent Questions on python

    Programming Languages