Skip to content

Instantly share code, notes, and snippets.

@shoter
Created September 17, 2018 10:39
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 shoter/6f9e0e774703cf19eca744528b27581c to your computer and use it in GitHub Desktop.
Save shoter/6f9e0e774703cf19eca744528b27581c to your computer and use it in GitHub Desktop.
Simple File deleter for windows 10
import os, time, sys
from win10toast import ToastNotifier
toast = ToastNotifier()
def str_join(*args):
return ''.join(map(str, args))
def warnAboutOldFiles(path, days):
path = "C:\\Users\\damian_laczak\\Downloads"
now = time.time()
fileCount = 0
for f in os.listdir(path):
fullPath = os.path.join(path, f)
if os.stat(fullPath).st_mtime < now - (days * 86400):
fileCount = fileCount + 1
if fileCount > 0:
toast.show_toast("Delete notifier", str_join(path, "\nYou have ", fileCount, " files that are at least ", days, " days old"))
def deleteOlderFielsThan(path, days):
path = "C:\\Users\\damian_laczak\\Downloads"
now = time.time()
for f in os.listdir(path):
fullPath = os.path.join(path, f)
if os.stat(fullPath).st_mtime < now - (days * 86400):
if os.path.isfile(fullPath):
os.remove(os.path.join(path, fullPath))
def warnAndDelete(path, daysWarn, daysDelete):
warnAboutOldFiles(path, daysWarn)
deleteOlderFielsThan(path, daysDelete)
warnAndDelete("C:\\Users\\damian_laczak\\Downloads", 60, 90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment