Python programming to delete VC temporary files and Debug directory method

  • 2020-05-27 05:58:36
  • OfStack

This article illustrates the programming method of Python to delete VC temporary files and Debug directory. I will share it with you for your reference as follows:


# *_* 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()

More about Python related topics: interested readers to view this site "Python file and directory skills summary", "Python skills summary text file", "Python URL skills summary", "Python pictures skills summary", "Python data structure and algorithm tutorial", "Python Socket programming skills summary", "Python function using skills summary", "Python string skills summary" and "Python introductory and advanced tutorial"

I hope this article is helpful for you to design Python program.


Related articles: