Skip to content

Instantly share code, notes, and snippets.

@PHLAK
Created March 24, 2012 21:40
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 PHLAK/2188297 to your computer and use it in GitHub Desktop.
Save PHLAK/2188297 to your computer and use it in GitHub Desktop.
Deletes files older than 14 days from a given folder.
import os
import time
path = "E:\\Downloads"
now = int(time.time())
dirList = os.listdir(path)
for fileName in dirList:
filePath = path + "\\" + fileName
modTime = int(os.path.getmtime(filePath))
if now - modTime >= 1209600:
print "Deleting %s" % filePath
os.remove(filePath)
print "Cleanup complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment