I have a very irregular list of list containing a folder structure, and I want to iterate through the list and check whether that folder/sub-folder exist or not.
folderStructure = [['Folder1', [subfolder1, [sub-sub-folder1, sub-sub-folder2]]], ['Folder2', [sub-folder2], [sub-folder3]], ['Folder3', [sub-folder4]], ['Folder4'], [file1, file2, file3]]
How can I test if this folder structure exist?
In order to actually check if the folder exists, you have to specify its path and use
os.path.exists. The difficult part is that the nested lists have strings that sometimes represent a folder's name, and other times a file name. I wrote a function that tests if the members of the supplied structure exist or not, and tries to determine if the content represents a folder name or not.