1. 程式人生 > >delete specific lines in a set of files in a folder

delete specific lines in a set of files in a folder

import os 

myinst = ['foo','bar']

def wipe_lines(folder):
    for (dirpath, dirnames, filenames) in os.walk('/Users/faramir/git/'+ folder):
        for filename in filenames:
            f = open(os.sep.join([dirpath, filename]),"r")
            lines = f.readlines()
            f.close()
            f = open(os.sep.join([dirpath,filename]),"w")
            for line in lines:
                if not line in copyright:
                    f.write(line)

for x in ['mos','unittest']:
    wipe_lines(x)