Python

로컬 경로 내 당일 날짜형식의 이름을 가진 파일 전체 업로드

Neeson.lee 2023. 3. 22. 09:33
import os
import datetime as dt
import boto3

x = dt.datetime.now()
date = x.strftime("%Y%m%d")
bucket = 'mybucket'
dir_path = "/log"
s3 = boto3.client('s3')

def log(in_path):
    for (dir_path, dir, files) in os.walk(in_path):
        for file in files:
            if date in file:
                yield os.path.join(dir_path, file)


for file_name in log(dir_path):
    res = s3.upload_file(file_name, bucket, file_name)