본문 바로가기
Python, API

[Python] os.walk - 하위폴더 내의 모든 파일 리스트 검색하기

by 오늘밤날다 2024. 5. 3.

 

https://docs.python.org/3/library/os.html#os.walk

 

os — Miscellaneous operating system interfaces

Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, s...

docs.python.org

 

 

import os

summary_filelist = []
for path, dir, files in os.walk(".."):
    for filename in files:
        path_file = path + "/" + filename
        summary_filelist.append(path_file)

print(summary_filelist)

 

현재 폴더를 포함한 하위 폴더들의 모든 파일목록을 리스트에 저장하는 코드