# -*- coding: cp936 -*-
import os
# 目的:查找一个目录下的包含指定字符串的文件
dir_name = raw_input("Please input the dir you want to find:/n")
find_str = raw_input("Please input the sting you want to find:/n")
def my_find(dir_name, find_str, results):
myfiles = os.listdir(dir_name)
for myfile in myfiles:
file_name = dir_name + "//" + myfile
if os.path.isfile(file_name):
f = open(file_name, 'r')
filer = f.read()
if(find_str in filer):
results.append(file_name)
f.close()
elif os.path.isdir(file_name):
my_find(file_name, find_str, results)
return results
results = []
results = my_find(dir_name, find_str, results)
for result in results:
print result