import os, sys
if __name__ == "__main__":
directory_name = ""
search_file = ""
if len(sys.argv) != 3:
print "Usage: python findfile.py <directory> <filename>"
sys.exit(1)
else:
directory_name = sys.argv[1]
search_file = sys.argv[2]
results, matches = [],[]
for dirpath, dirnames, filenames in os.walk(directory_name):
for subdirectory in dirnames:
os.path.join(dirpath, subdirectory)
for filename in filenames:
print dirpath + "/" + filename
if filename == search_file:
results.append(dirpath + "/" +filename)
print dirpath + "/" + filename
elif filename.startswith(search_file) or filename.endswith(search_file):
matches.append(dirpath + "/" + filename)
if len(results) != 0:
print "Found file(s): "
for filepath in results:
print filepath
else:
if len(matches) != 0:
print "Found possibe matches:"
for filepath in matches:
print filepath
|