我正在尝试根据创建日期存档旧文件。我的数据从 2010 年 12 月 17 日开始,所以我将其设置为基准日期并从那里递增。这是我的代码
import os, time, tarfile
from datetime import datetime, date, timedelta
import datetime
path = "/home/appins/.scripts/test/"
count = 0
set_date = '2010-12-17'
date = datetime.datetime.strptime(set_date, '%Y-%m-%d')
while (count < 2):
date += datetime.timedelta(days=1)
tar_file = "nas_archive_"+date.strftime('%m-%d-%y')+".tgz"
log_file = "archive_log_"+date.strftime('%m-%d-%y')
fcount = 0
f = open(log_file,'ab+')
#print date.strftime('%m-%d-%y')
for root, subFolders, files in os.walk(path):
for file in files:
file = os.path.join(root,file)
file = os.path.join(path, file)
filecreation = os.path.getctime(file)
print datetime.fromtimestamp(filecreation)," File Creation Date"
print date.strftime('%m-%d-%y')," Base Date"
if filecreation == date:
tar.add(file)
f.write(file + '\n')
print file," is of matching date"
fcount = fcount + 1
f.close()
count += 1
文件创建变量正在获取浮点值。如何使用它与我的基准日期进行比较?