| 1 |
ninoborges |
8 |
## LookInIPF
|
| 2 |
|
|
## This is a program that will hopefully help me in finding all instances of a word in all of my IPF's. This was
|
| 3 |
|
|
## developed for a project that need to find all instances of the server name MWBBPDC and Replace them with RIC1.
|
| 4 |
|
|
|
| 5 |
|
|
import os
|
| 6 |
|
|
|
| 7 |
|
|
|
| 8 |
|
|
def listFiles(arg, dirname, names):
|
| 9 |
|
|
print "I'm now looking in %s for files with an %s ext." %(dirname,arg[0])
|
| 10 |
|
|
for x in names:
|
| 11 |
|
|
ext = x[-3:]
|
| 12 |
|
|
ext = ext.upper()
|
| 13 |
|
|
#print ext
|
| 14 |
|
|
if ext == arg[0]:
|
| 15 |
|
|
file = x + "\n"
|
| 16 |
|
|
o.write(file)
|
| 17 |
|
|
#print x
|
| 18 |
|
|
searchIPF(x,dirname,arg[2])
|
| 19 |
|
|
|
| 20 |
|
|
def searchIPF(file,path,string):
|
| 21 |
|
|
absPath = path+"\\"+file
|
| 22 |
|
|
r = open(absPath,'r')
|
| 23 |
|
|
contents = r.readlines()
|
| 24 |
|
|
for i in contents:
|
| 25 |
|
|
i = i.upper()
|
| 26 |
|
|
result = i.find(string)
|
| 27 |
|
|
if result != -1:
|
| 28 |
|
|
message = "%s has the word %s in it \n" % (file,string)
|
| 29 |
|
|
testfile = open(r"U:\foundelite.txt",'a')
|
| 30 |
|
|
testfile.write(message)
|
| 31 |
|
|
r.close()
|
| 32 |
|
|
|
| 33 |
|
|
startLocation = r"u:\nino\Active SMS Installer Files"
|
| 34 |
|
|
o=open(r"U:\ListOfIPFs.txt",'w')
|
| 35 |
|
|
arguments = ("IPF",o,"MWBBPDC")
|
| 36 |
|
|
os.path.walk(startLocation,listFiles,arguments)
|
| 37 |
|
|
o.close() |