Skip to content

Instantly share code, notes, and snippets.

@dansku
Created December 28, 2022 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dansku/19e19d507bffc21da68a85e45e7aa3f5 to your computer and use it in GitHub Desktop.
Save dansku/19e19d507bffc21da68a85e45e7aa3f5 to your computer and use it in GitHub Desktop.
Delete older download files
import os, time
dir_path = ""
def file_age(filepath):
age = time.time() - os.path.getmtime(filepath)
minutes = int(age) / 60
hours = minutes / 60
days = hours / 24
return days
# Iterate directory
for path in os.listdir(dir_path):
# check if current path is a file
if os.path.isfile(os.path.join(dir_path, path)):
filepath = os.path.join(dir_path, path)
age =file_age(filepath)
if age > 60:
print("File should be deleted", filepath, age)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment