桌面经常放了一堆文件,
写个脚本定期运行清理一下
代码如下:
#!/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~'
本文介绍了一个Python脚本,该脚本可以自动整理桌面文件,将除特定文件外的所有文件移动到以当前时间戳命名的新文件夹中,实现桌面的周期性整洁。
3470

被折叠的 条评论
为什么被折叠?



