辛夷坞

涧户寂无人,纷纷开且落

By - Christen

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()

Leave a Reply

Your email address will not be published.
*
*