【发布时间】:2022-01-18 21:57:08
【问题描述】:
所以我正在制作一个 GUI,它需要一个包含预配置目录的目录结构的列表。格式可能是这样的:
{"base_folder":
[
"file1.txt",
"file2.txt",
{"directory1":
[
"nested_image.png",
{"nested_directory":
[
"deep_video.mp4",
"notes.txt"
]
},
"another_image.png",
"not_a_file_type.thisisafile"
]
},
"game.exe",
"mac_port_of_game.app", # yeah I know that a .app is a bundle but can't be bothered
# to make the entire bundle structure
"linux_port_of_game.elf",
{"coding_stuff":
[
"code.py",
"morecode.c"
]
}
[
}
格式不一定要完全一样,但是否有内置函数,可能在os 模块中可以做到这一点?
【问题讨论】:
-
我不这么认为,但是用
os.walk()写应该不难。 -
那么,您在查看文档时发现了什么?
-
不,没有内置的——为什么会有?
-
@TheMystZ 您是否尝试过建议的解决方案?