# To delete nodes starting with some prefix string
import os
from time import strftime,localtime
def del_p_999(fpath,str):
print ('--------------------------------------------------------------------')
print fpath
print "Start Time : " + strftime("%H:%M:%S",localtime())
filein = open(fpath,'r')
inputstr = filein.read()
filein.close()
lines=inputstr.splitlines(1)
sw = 0
linecount = 0
outputstr=''
totalnodes = 0
fileout=open(fpath,'w')
for line in lines:
if(line.startswith('createNode')):
sw = 0
if line.find(str) != -1:
sw = 1
totalnodes += 1
else:
fileout.write(line)
sw = 0
else:
if sw==1:
continue
else:
fileout.write(line)
sw = 0
fileout.close()
print ("\nTotal Nodes Deleted : ")
print totalnodes
print ("\nEnd Time : " + strftime("%H:%M:%S",localtime())+'\n')
basedir=raw_input('Enter Root Path : ')
str=raw_input('Enter Node Prefix : ')
for root,dirs,files in os.walk(basedir):
for f in files:
fpath=os.path.join(root, f)
if(f.endswith('.ma')):
del_p_999(fpath,str)