** 问题 ** 我正在尝试打开(在 python 中)超过当前名称中日期戳 3 天的文件。示例:2016_08_18_23_10_00 - JPN - MLB - Mickeymouse v Burgerface.ply。到目前为止,我可以创建一个日期变量,但是我不知道如何在文件名中搜索这个变量。我想我需要先将其转换为字符串?
from datetime import datetime, timedelta
import os
import re
path = "C:\Users\michael.lawton\Desktop\Housekeeper"
## create variable d where current date time is subtracted by 3 days ##
days_to_subtract = 3
d = datetime.today() - timedelta(days=days_to_subtract)
print d
## open file in dir where date in filename = d or older ##
for filename in os.listdir(path):
if re.match(d, filename):
with open(os.path.join(path, filename), 'r') as f:
print line,
任何帮助都感激不尽