I am trying to archive old files based on creation date. I have data starting from 12-17-2010 so i am setting this as base date and incrementing from there. Here is my code
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
filecreation variable is getting float value. How can I use it to compare with my base date?