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

파이썬 Python 특정 날짜 이후에 수정된 파일 가져오기

by Pymac 2025. 5. 5.
반응형

# 특정 날짜 이후에 수정된 파일 가져오기

 

수정일 기준으로 필터링할 때는 `datetime`과 `os.path.getmtime()`을 함께 사용합니다.

 

import os

import datetime

 

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

target_time = datetime.datetime(2024, 1, 1).timestamp()  # 2024년 1월 1일 이후

 

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

                if os.path.isfile(os.path.join(folder_path, f)) and

                   os.path.getmtime(os.path.join(folder_path, f)) > target_time]

 

print(recent_files)

 

보고서나 로그에서 특정 기간 이후의 데이터만 수집할 때 유용합니다.

 

반응형