0

I've not got very far with this, I'm trying to check the creation time of a file and simply compare the date (only the day, month and year) with todays date (again only day, month and year)

import os.path, time
import datetime
fulldate = time.ctime(os.path.getctime("file.xlsx"))

Anyone know how I can convert the date and then check against todays date?

Ryflex
  • 5,559
  • 25
  • 79
  • 148
  • See http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python – joel3000 Feb 21 '14 at 01:30

1 Answers1

1
import os.path, time
from datetime import datetime
from time import mktime

fulldate = time.ctime(os.path.getctime("file.xlsx"))
struct = time.strptime(fulldate)
filetime = datetime.fromtimestamp(mktime(struct))
filedate = filetime.replace(hour=0, minute=0, second=0, microsecond=0)

if filetime < datetime.now():
  print "The file is quite old"
else:
  print "The file is not so old"
mre
  • 1,813
  • 4
  • 28
  • 37
  • That's pretty much it, it's not quite working for me but but it's so close, I can hacky fix it by chosing the first 10 characters only but basically I don't need to be comparing the times of the files, just the dates – Ryflex Feb 21 '14 at 12:22