@
hahastudio 大神看我代码,为啥匹配不到呢
# -*- coding: utf-8 -*-
#########################################################################
# Author: Yao Kun
# Created Time: 五 8/ 8 07:42:26 2014
# File Name:
testmac.py# Description:
#########################################################################
import os
# 用于获得操作系统信息
import platform
import fnmatch
print "尝试删除扩展名为空,或者是不需要同步的文件"
sys = platform.system()
if sys == "Darwin":
sys = "Mac OS X"
print "Your system is", sys, ", this is a delete-file script..."
else:
print "您的操作系统是", sys, ",这是删除文件脚本"
def iterfindfiles(path, fnexp):
for root, dirs, files in os.walk(path):
# 遍历某个目录
for filename in fnmatch.filter(files, fnexp):
yield os.path.join(root, filename)
if sys == "Mac OS X":
search_path = r"/Users/mac-prisonbreak/百度云同步盘/"
else:
search_path = r"D:/百度云/Project"
print "Your current search dir is", search_path
flag = False
command = "check"
logfile = open("delete_log.txt", "w+")
for filename in iterfindfiles(search_path, "^([^\\]*)\.(\w+)$"):
print filename
logfile.write("\n"+filename)
# 删除是危险操作,需要确认
if command == "all" or command == "yes":
os.remove(filename)
if command == "yes":
command = "check"
elif command == "none":
pass
print "Do nothing"
else:
command = raw_input()
#关闭文件
logfile.close()