この関数(特定の文字列のディレクトリを検索する)ですべてのサブディレクトリも検索するようにしようとしています。これを再帰的に実行します。私はPythonを始めるのに十分な知識がありません。どんなガイダンスも素晴らしいでしょう。
ありがとう!
def grep(regex, base_dir):
matches = list()
for filename in os.listdir(base_dir):
full_filename = os.path.join(base_dir, filename)
if not os.path.isfile(full_filename):
continue
with open(os.path.join(base_dir, filename)) as fh:
content = fh.read()
matches = matches + re.findall(regex, content)
return matches