aigems commited on
Commit
826a643
·
1 Parent(s): 10c367b
Files changed (2) hide show
  1. out.py +35 -0
  2. package.json +1 -1
out.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ def get_all_files(directory, exclude=None):
4
+ if exclude is None:
5
+ exclude = {'.git', '.gitattributes'}
6
+
7
+ file_list = []
8
+ for root, dirs, files in os.walk(directory, topdown=True):
9
+ # 从 dirs 列表中移除要排除的目录
10
+ dirs[:] = [d for d in dirs if d not in exclude]
11
+
12
+ for file in files:
13
+ if file not in exclude:
14
+ file_list.append(os.path.join(root, file))
15
+ return file_list
16
+
17
+ def write_file_contents(file_list, output_file):
18
+ with open(output_file, 'w', encoding='utf-8') as out:
19
+ for file_path in file_list:
20
+ out.write(f"文件名:{file_path}\n")
21
+ out.write("文件内容:\n")
22
+ try:
23
+ with open(file_path, 'r', encoding='utf-8') as f:
24
+ content = f.read()
25
+ out.write(content)
26
+ except Exception as e:
27
+ out.write(f"无法读取文件内容: {str(e)}\n")
28
+ out.write("\n\n" + "-"*50 + "\n\n")
29
+
30
+ if __name__ == "__main__":
31
+ current_directory = os.getcwd()
32
+ exclude_list = {'.git', '.gitattributes'} # 可以根据需要添加更多要排除的项
33
+ file_list = get_all_files(current_directory, exclude_list)
34
+ write_file_contents(file_list, 'output.txt')
35
+ print("文件内容已输出到 output.txt")
package.json CHANGED
@@ -21,6 +21,6 @@
21
  "jest": "^27.0.6"
22
  },
23
  "engines": {
24
- "node": ">=14.0.0"
25
  }
26
  }
 
21
  "jest": "^27.0.6"
22
  },
23
  "engines": {
24
+ "node": ">=18.0.0"
25
  }
26
  }