############################################################################
# #
# This program seeks out every copy of "starcraft.exe" in the computer #
# and deletes them. #
# Created by Matt in Python 2.5 May 2007. #
# #
############################################################################
import os
def file_find(folder):
"""search for a filename fname starting in folder"""
for root, dirs, files in os.walk(folder):
for file in files:
# make search case insensitive
if fname.lower() == file.lower():
return os.path.join(root)
return None
def deleteFileSearched():
global COUNTER
os.remove(trueResult)
print trueResult + " deleted successfully..."
COUNTER += 1
def main():
# file to search for ...
global fname
global folder
global trueResult
global allfiles
li2 = ["stardat.mpq", "starcraft.exe", "Local.dll",
"storm.dll", "Smack32.dll"]
li = ["c:\\", "d:\\", "e:\\", "f:\\"]
for fname2 in li2:
fname = fname2
# folder to start search ...
for folder in li:
result = file_find(folder)
if result == None:
print fname, "not found in", folder
continue
trueResult = "<A href="file://\\".join((result">\\".join((result, fname))
print "File found -->", trueResult
deleteFileSearched()
return True
COUNTER = 0
killSwitch = main()
while killSwitch == False:
if killSwitch == True:
break
killSwitch = main()
print COUNTER, "files deleted"
I need a way to make this loop until it doesn't find any file in any directory.... I can't figure out how to make it do that.