std = sorted(files, key=lambda file: (os.path.dirname(file), os.path.
    basename(file)))
print(std[0])
for i in range(1, len(std)):
    if os.path.dirname(std[i]) != os.path.dirname(std[i - 1]):
        pass
File paths hierarchial sort in python