-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_prompt.py
More file actions
21 lines (19 loc) · 969 Bytes
/
write_prompt.py
File metadata and controls
21 lines (19 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
def combine_files_to_prompt_context(directory, output_file):
with open(output_file, 'w', encoding='utf-8') as outfile:
# 使用 os.walk 递归遍历目录
for root, _, files in os.walk(directory):
for filename in files:
file_path = os.path.join(root, filename)
# 排除 write_prompt.py 本身
if filename == "write_prompt.py":
continue
# 只处理 .py 文件
if filename.endswith('.py'):
with open(file_path, 'r', encoding='utf-8') as infile:
relative_path = os.path.relpath(file_path, directory)
outfile.write(f"--- Start of {relative_path} ---\n")
outfile.write(infile.read())
outfile.write(f"\n--- End of {relative_path} ---\n\n")
# 调用函数
combine_files_to_prompt_context('./CodeGraph', 'output.txt')