import os
dirname="C:\\Users\\haier\\Desktop\\new"

def walk(path):
    for item in os.listdir(path):
        subpath = os.path.join(path, item)
        #subpath=subpath.replace('\\','\\\\')
        print subpath
        for i in open(subpath):
            pass#print i
        ffrom=open(subpath,'r')
        fto=open(subpath+"1",'w')
        while True:
            l=ffrom.readline()
            if not l:
                break
            if 'endif' in l:
                print l
                l=l.replace('endif','end')
                print l
            elif 'endwhile' in l:
                print l
                l=l.replace('endwhile','end')
                print l                
            # if '\"' in l:
                # print l
                # l=l.replace('\"','\'')
                # print l
              #  print l
               # tmp=l.split("\"")
                #l=tmp[0]+"\'"+tmp[1]
            fto.write(l)                      
        ffrom.close()
        fto.close()

def dele(path):
   for item in os.listdir(path):
        subpath = os.path.join(path, item)
       # subpath=subpath.replace('\\','\\\\')

            
        if os.path.exists(subpath+"1"):
            ffrom=open(subpath+"1",'r')
            fto=open(subpath,'w')
            while True:
                l=ffrom.readline()
                if not l:
                    break
                fto.write(l)                      
            ffrom.close()
            fto.close()
            os.remove(subpath+"1")

        
walk(dirname)
dele(dirname)

 

相关文章:

  • 2021-10-03
  • 2021-11-17
  • 2021-11-27
  • 2022-12-23
  • 2022-02-19
  • 2021-08-05
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2021-10-09
  • 2021-11-22
  • 2022-12-23
相关资源
相似解决方案