import os import pandas as pd import csv PATH = r'C:/Users/Desktop/users' file_ls = [] max_depth = 0 for path, dir, files in os.walk(PATH): for file in files: current = os.path.join(path, file).replace('\\', '/') file_ls.append(current) if len(current.split('/')) > max_depth: max_depth = len(current.split('/'))