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程序设计有所帮助。

相关文章

朴素贝叶斯Python实例及解析

本文实例为大家分享了Python朴素贝叶斯实例代码,供大家参考,具体内容如下 #-*- coding: utf-8 -*- #添加中文注释 from numpy import *...

python实现dnspod自动更新dns解析的方法

复制代码 代码如下:def ddns():"""用当前ip更新ddns"""headers = {"Content-type": "application/x-www-form-urle...

使用Nginx+uWsgi实现Python的Django框架站点动静分离

由于: Django处理静态文件不太友好; 以后有可能需要处理php或者其他资源的请求; 所以考虑结合nginx,使用nignx做它擅长的路由分发功能;同时做动静分离,即Http请求统一...

Python3 加密(hashlib和hmac)模块的实现

以下代码以Python3.6.1为例 hashlib : 不可逆加密 hmac : 不可逆键值对方式加密 hashlib模块简介: hashlib模块为不同的安全哈希/安全散...

python 对类的成员函数开启线程的方法

如下所示: # -*- coding: utf-8 -*- import threading import thread import time class Test(objec...