Skip to content

Instantly share code, notes, and snippets.

@chenzixin
Last active December 28, 2015 20:09
Show Gist options
  • Save chenzixin/7555639 to your computer and use it in GitHub Desktop.
Save chenzixin/7555639 to your computer and use it in GitHub Desktop.
Delete Expired File

Delete Expired File

Programed by Bingal, which will delete the files in current directory created 30 days ago.:

#!/usr/bin/python
# encoding: utf-8

def main():
	import os,time
	for fn in os.listdir(os.curdir):
		fp = os.path.join(os.curdir,fn)
		if not os.path.isfile(fp):
			continue
		if fn.startswith('.') or fn == 'delete_expired_file.py':
			continue
		ctime = int((time.time()-os.stat(fp).st_ctime)*1.0/(60*60*24))
		if ctime > 30:
			os.remove(fp)
			print fn,ctime

if __name__=="__main__":
	main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment