본문 바로가기
python3 selenium/Folder , File

파이썬 Python 파일 크기 + 확장자 복합 필터링

by Pymac 2025. 5. 5.
반응형

# 파일 크기 + 확장자 복합 필터링

 

파일 확장자와 크기 조건을 동시에 만족하는 파일만 가져오려면 아래처럼 조합할 수 있습니다.

 

import os

 

folder_path = 'C:/Users/username/Documents/myfolder'

 

filtered_files = [f for f in os.listdir(folder_path)

                  if f.endswith('.csv') and

                     os.path.getsize(os.path.join(folder_path, f)) > 50000 and

                     os.path.isfile(os.path.join(folder_path, f))]

 

print(filtered_files)

 

예: 50KB 이상 .csv 파일만 수집 가능

반응형