删除qq文件夹中2013年12-31之前的文件
import os import time import datetime timeline = datetime.datetime(2013,12,31) tl = time.mktime(timeline.timetuple()) rootdir = r'C:Documents and SettingsAdministrator.CHINA-C58199F8BMy DocumentsTencent FilesxxxxxxxxImage' for basedirs, dirs, files in os.walk(rootdir): for f in files: f_full = os.path.join(basedirs, f) print f_full if os.path.getmtime(f_full) < tl: os.remove(f_full)
os.walk实现的是遍历每个目录