Created
December 28, 2022 13:35
-
-
Save dansku/19e19d507bffc21da68a85e45e7aa3f5 to your computer and use it in GitHub Desktop.
Delete older download files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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