I wrote this code in c# to check if a file is out of date:
DateTime? lastTimeModified = file.getLastTimeModified();
if (!lastTimeModified.HasValue)
{
//File does not exist, so it is out of date
return true;
}
if (lastTimeModified.Value < DateTime.Now.AddMinutes(-synchIntervall))
{
return true;
} else
{
return false;
}
How do I write this in python?
I tried this in python.
statbuf = os.stat(filename)
if(statbuf.st_mtime < datetime.datetime.now() - self.synchIntervall):
return True
else:
return False
I got the following exception
message str: unsupported operand type(s) for -: 'datetime.datetime' and 'int'
You want to use the
os.path.getmtimefunction (in combination with thetime.timeone). This should give you an idea: