桌面经常放了一堆文件,
写个脚本定期运行清理一下
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
dir1='D:\userdata\yunpebai\Desktop'
marks = '_box'
os.chdir(dir1)
def timestamp():
tp = time.strftime('%Y-%m-%d_%H-%M-%S',time.localtime(time.time()))
return tp
def collectSet(f):
a = (f != 'desktop.ini' and f != 'clearDTP.py' and f != 'Archive.py' and 'box' not in f and 'archive' not in f)
return a
targetDir = timestamp() + marks
pan = os.path.exists(dir1 + os.sep + targetDir)
if not pan:
os.mkdir(targetDir)
for f in os.listdir(dir1):
if collectSet(f):
sCmd=' '.join(['move',f,targetDir + os.sep])
print sCmd
if os.system(sCmd) == 0:
print 'move OK~'