생성 날짜를 기준으로 오래된 파일을 보관하려고합니다. 데이터가 12-17-2010에서 시작하므로 기본 날짜로 설정하고 거기서부터 증가시킵니다. 다음은 내 코드입니다파일 생성 날짜 비교
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 변수가 부동 소수점 값을 가져옵니다. 기준일과 비교하기 위해 어떻게 사용할 수 있습니까?
레코드의 경우, 'ctime'은 파일 생성 날짜가 아니다 ... – twalberg
'count <2' ... 이것은 2 일만 비교할 것이다. – tdelaney
예. 나는 작은 세트부터 시작하고있다. 코드가 작동하기 시작하면 i가 더 늘어날 것입니다. – user2501825