`

python 删除目录下文件

阅读更多

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脚本语言也好。存在总有必然性,总有其价值。不管哪门你都没有资格去鄙视他。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics