분류 전체보기 97

디렉토리 · 파일 구조 출력

def file_tree(path, level=0, prefix=""): # 상위 폴더를 출력 if level == 0: print(f"{path}/") # os.walk를 통해 폴더를 순차적으로 탐색 for root, dirs, files in os.walk(path): # 현재 디렉토리의 상대 경로에서 깊이를 구함. depth = root.replace(path, '').count(os.sep) # 디렉토리 깊이에 맞는 들여쓰기 - 각 디렉토리 및 파일의 앞에 추가할 들여쓰기를 만들기 위한 문자열 indent = "│ " * (depth - 1) + "└── " if depth > 0 ..