Reputation: 23
I have a folder, I need to check if since last 2 minutes, no changes have been made to it. so I plan to check the last modified time of folder by using this :
os.stat(currFolder).st_mtime;
now how to take current time in such a way and subtract it so that I can know that since last 2 mins, no modification has been done.
I checked on google, but seems format of time was confusing to me. Can someone please help on this ?
Regards
Upvotes: 0
Views: 804
Reputation: 9047
You can convert the timestamp
to the python datetime
object and check the difference between it and now.
import datetime
def is_folder_updated(threshold_in_minutes = 2):
last_forder_update_timestamp = os.stat('./').st_mtime
last_folder_update_datetime = datetime.datetime.fromtimestamp(last_forder_update_timestamp)
current_datetime = datetime.datetime.now()
difference = current_datetime - last_folder_update_datetime
return (difference.total_seconds()/60) < threshold_in_minutes
is_folder_updated()
Upvotes: 1