'Deleting files/folders older than one hour in python
I want to delete the directories older than 1 hour in python. I would like to see the creation time of each folder and delete any folder older than 1 hour
Solution 1:[1]
I used this function to get the time difference between a directory and current time in minutes
def get_total_mins(dir):
x = time.ctime(os.path.getmtime(dir))
folder_time = x[11:19]
fld_hrs = int(folder_time[0:2])
fld_mins = int(folder_time[3:5])
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
crnt_hrs = int(current_time[0:2])
crnt_mins = int(current_time[3:5])
total_mins = abs(crnt_mins - fld_mins) + (abs(crnt_hrs - fld_hrs)*60)
return total_mins
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Omar |
