반응형
재귀적으로 서브 디렉토리 목록 및 서브 디렉토리별 파일 개수를 출력하는 파이썬 코드입니다.
2022. 5. 28 최초작성
import os path = './test' # 서브 디렉토리 목록 출력 for root, subdirs, files in os.walk(path): for d in subdirs: fullpath = root + '/' + d print(fullpath) print() # 서브 디렉토리별 파일 개수 출력 for root, subdirs, files in os.walk(path): if len(files) > 0: print(root, len(files)) |
반응형