你可以使用 Python 的 os
模块来读取目录下的多个子目录以及它们包含的文件,然后将它们的内容写入到一个新的文件中。
下面是一个简单的示例:
import os
root_dir = '/path/to/root/directory'
output_file = 'output.txt'
with open(output_file, 'w') as f:
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames: