반응형

재귀적으로 서브 디렉토리 목록 및 서브 디렉토리별 파일 개수를 출력하는 파이썬 코드입니다.



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))




반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts