我有一个非常不规则的包含文件夹结构的列表列表,我想遍历该列表并检查该文件夹/子文件夹是否存在。你知道吗
folderStructure = [['Folder1', [subfolder1, [sub-sub-folder1, sub-sub-folder2]]], ['Folder2', [sub-folder2], [sub-folder3]], ['Folder3', [sub-folder4]], ['Folder4'], [file1, file2, file3]]
如何测试此文件夹结构是否存在?你知道吗
我不确定子文件夹是什么,但如果您在不规则形状的数组中查找字符串,这将起作用。您应该通过阅读深度优先搜索来了解这是怎么做的。你知道吗
将文件夹结构作为第一个参数传递,将要搜索的文件夹的名称作为第二个参数传递。你知道吗
为了实际检查文件夹是否存在,必须指定其路径并使用
os.path.exists
。困难的是嵌套列表中的字符串有时表示文件夹名,有时表示文件名。我编写了一个函数,用于测试所提供结构的成员是否存在,并尝试确定内容是否表示文件夹名称。你知道吗相关问题 更多 >
编程相关推荐