Python编程实现删除VC临时文件及Debug目录的方法

yipeiwu_com6年前Python基础

本文实例讲述了Python编程实现删除VC临时文件及Debug目录的方法。分享给大家供大家参考,具体如下:

# *_* coding=gb2312 *-*
import os
import os.path
import shutil
invalidFileExtList =[".ncb",".user"]
invalidDirectory=["Debug"]
def InternalDeleteInvalidFile(str):
  bFlag=False
  if os.path.isdir(str):
    basename =os.path.basename(str)
    for dir in invalidDirectory:
      if basename == dir:
        bFlag = True
        break
    if bFlag:
      shutil.rmtree(str,True)
      print "we are deleting ",str
    else:
      WalkDirectory(str)
  else:
    tup = os.path.splitext(str)
    for ext in invalidFileExtList:
      if tup[1] == ext:
        os.remove(str)
        print str
        break
def WalkDirectory(str):
  fileList =os.listdir(str)
  for xxx in fileList:
    InternalDeleteInvalidFile(str+"\\"+xxx)
def DeleteInvalidFile():
  str = os.getcwd()
  print str
  InternalDeleteInvalidFile(str)
  print "hello world"
if __name__ =='__main__':
  DeleteInvalidFile()

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python文件与目录操作技巧汇总》、《Python文本文件操作技巧汇总》、《Python URL操作技巧总结》、《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

相关文章

对Python3 goto 语句的使用方法详解

对Python3 goto 语句的使用方法详解

熟悉 C 语言的小伙伴一定对 goto 语句不陌生,它可以在代码之间随意的跳来跳去,但是好多老鸟都告诫大家,不要使用 goto,因为 goto 会使你的代码逻辑变的极其混乱。 但是有时候...

对python多线程中Lock()与RLock()锁详解

资源总是有限的,程序运行如果对同一个对象进行操作,则有可能造成资源的争用,甚至导致死锁 也可能导致读写混乱 锁提供如下方法: 1.Lock.acquire([blocking]) 2.L...

python matplotlib中文显示参数设置解析

python matplotlib中文显示参数设置解析

最近在学习python著名的绘图包matplotlib时发现,有时候图例等设置无法正常显示中文,于是就想把这个问题解决了。 PS:本文仅针对Windows,其他平台仅供参考。 原因 大致...

Python箱型图处理离群点的例子

Python箱型图处理离群点的例子

首先我们简单地区分一下离群点(outlier)以及异常值(anomaly): 离群点: 异常值: 个人觉着异常值和离群点是两个不同的概念,当然大家在数据预处理时对于这两个概念不做细致...

python类中super()和__init__()的区别

单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(self): print 'Base create'...