0

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

Omar
  • 297
  • 5
  • 16
  • 1
    Does this answer your question? [How do I get file creation and modification date/times?](https://stackoverflow.com/questions/237079/how-do-i-get-file-creation-and-modification-date-times) – doa4321 May 24 '22 at 08:29

1 Answers1

0

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
Omar
  • 297
  • 5
  • 16