import os
import shutil
def CleanDir( Dir ):
if os.path.isdir( Dir ):
paths = os.listdir( Dir )
for path in paths:
filePath = os.path.join( Dir, path )
if os.path.isfile( filePath ):
try:
os.remove( filePath )
except os.error:
autoRun.exception( "remove %s error." %filePath )#引入logging
elif os.path.isdir( filePath ):
if filePath[-4:].lower() == ".svn".lower():
continue
shutil.rmtree(filePath,True)
return True
Dir = "D:\\Temp"
CleanDir(Dir)
今天是学习python的第三天,被羞辱了。刚开始没有引入import shutil 。而这句 shutil.rmtree(filePath,True) 提示未定义。自己却不知道该引入哪个包。问网友就被笑话了。
还有发现那个群好多人BS 学java的,我觉得心胸狭隘。技术搞得也像台湾政党间互相攻击一样。。。。
其实java 、C++、C、汇编、或者web开发中常见的jsp,php,asp,net 或者javascript、python脚本语言也好。存在总有必然性,总有其价值。不管哪门你都没有资格去鄙视他。
本文分享了一个Python脚本,用于递归地清理指定目录下的文件及子目录(除了.svn目录)。作者通过这次经历强调了不同编程语言的价值,并反思了开发者社区中存在的偏见。

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



