可以使用Python语言编写脚本来实现此目的。具体的步骤如下所述:
下面是一个示例代码,可以实现此目的:
import os
def search_files(root_dir, search_str, output_file):
with open(output_file, 'w') as f:
for subdir, dirs, files in os.walk(root_dir):
for file in files:
file_path = os.path.join(subdir, file)
if os.path.isfile(file_path):
with open(file_path, 'r') as curr_file:
contents = curr_file.read()
if search_str in contents:
f.write('FIND IN {0}: {1}\n'.format(file_path, contents))
search_str = 'your search string'
root_dir = 'your root path'
output_file = 'output.txt'
search_files(root_dir, search_str, output_file)
在脚本中,您需要简单地替换“search_str”、“root_dir”和“output_file”,以指定特定字符,根路径和输出文件的路径。此外,您可以通过修改“FIND IN”字符串来指定您想要在新文件中打印的信息。