Skip to content

Commit f356fe9

Browse files
authored
Add files via upload
1 parent d2c55be commit f356fe9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

main.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,34 @@ def dropEvent(self, event):
6363

6464
def generate_file_structure(self, root_dir, output_file):
6565
with open(output_file, 'w', encoding='utf-8') as f:
66-
f.write(self.get_directory_tree(root_dir))
66+
f.write(self.get_directory_tree(root_dir, output_file))
6767
for dirpath, _, filenames in os.walk(root_dir):
6868
for filename in filenames:
6969
filepath = os.path.join(dirpath, filename)
70-
f.write(f"### {filepath} ###\n")
70+
# 忽略输出文件
71+
if filepath == output_file:
72+
continue
73+
normalized_path = os.path.normpath(filepath).replace('\\', '/')
74+
f.write(f"\n<file path=\"{normalized_path}\">\n")
7175
try:
7276
with open(filepath, 'r', encoding='utf-8') as file:
7377
content = file.read()
74-
f.write(content + "\n\n")
78+
f.write(content + "\n")
7579
except Exception as e:
76-
f.write(f"无法读取文件内容: {e}\n\n")
80+
f.write(f"无法读取文件内容: {e}\n")
81+
f.write("</file>\n")
7782

78-
def get_directory_tree(self, root_dir):
83+
def get_directory_tree(self, root_dir, output_file):
7984
tree = []
8085
for dirpath, dirnames, filenames in os.walk(root_dir):
8186
level = dirpath.replace(root_dir, '').count(os.sep)
8287
indent = '│ ' * (level)
8388
tree.append(f"{indent}├── {os.path.basename(dirpath)}/")
8489
subindent = '│ ' * (level + 1)
8590
for f in filenames:
91+
# 忽略输出文件
92+
if os.path.join(dirpath, f) == output_file:
93+
continue
8694
tree.append(f"{subindent}├── {f}")
8795
return "\n".join(tree) + "\n"
8896

0 commit comments

Comments
 (0)