python3 selenium/Folder , File
파이썬 Python 하위 폴더 포함 전체 파일 가져오기
Pymac
2025. 5. 5. 12:23
반응형
# 파이썬으로 하위 폴더 포함 전체 파일 가져오기
`glob`의 `recursive=True` 옵션을 이용하면 하위 폴더까지 모두 탐색할 수 있습니다.
import glob
import os
folder_path = 'C:/Users/username/Documents/myfolder'
all_files = glob.glob(f"{folder_path}/**/*", recursive=True)
files_only = [f for f in all_files if os.path.isfile(f)]
print(files_only)
이렇게 하면 폴더 아래의 모든 파일이 리스트로 수집됩니다.
반응형