import os
import datetime
import shutil
import subprocess
dir_to_clean = '/home/www_remote/mishu/public/tmp'
dir_list = os.listdir(dir_to_clean)
today = datetime.datetime.today()
formatted_today = today.strftime('%Y%m%d')
int_today = int(formatted_today)
for dirs in dir_list:
dirs_path = dir_to_clean + os.path.sep + dirs
int_dirs = int(dirs)
if (int_today-int_dirs) > 7:
linux下执行
subprocess.Popen(('rm -rf %s' % dirs_path), stdout=subprocess.PIPE, shell=True)