1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

import os
import pyperclip # 需要安装 pip install pyperclip

def generate_tab_tree(directory, level=0, exclude_dirs=[], exclude_exts=[]):
try:
files = sorted(os.listdir(directory)) # 按字母排序,方便阅读
except PermissionError:
return "" # 避免访问无权限目录时报错

content = ""
for file in files:
path = os.path.join(directory, file)

# 过滤掉指定的文件夹
if os.path.isdir(path) and file in exclude_dirs:
continue

# 过滤掉指定后缀的文件
if os.path.isfile(path) and any(file.endswith(ext) for ext in exclude_exts):
continue

# 使用制表符(Tab)进行缩进
content += "\t" * level + file + "\n"

# 递归处理子文件夹
if os.path.isdir(path):
content += generate_tab_tree(path, level + 1, exclude_dirs, exclude_exts)

return content

# 设置你的目标文件夹路径
directory = r"C:\malaysiaMainPackage\malaysiaMainPackage\Assets\_GameWrap\Editor" # 你可以修改为你的目录路径

# 设置要排除的文件夹
exclude_dirs = ["ThirdParty"]

# 设置要排除的文件后缀(如 .lua、.meta、.proto) ".lua",
exclude_exts = [".meta", ".proto"]

# 生成树状结构
tree_structure = generate_tab_tree(directory, exclude_dirs=exclude_dirs, exclude_exts=exclude_exts)

# 复制到剪贴板
pyperclip.copy(tree_structure)
print("层级结构已复制到剪贴板,可以直接粘贴!🎯")