'Create list of zipped folders that contain specific file extensions in python

I am attempting to create lists of folders depending on the file extensions that exist within those folders. I have a folder that contains three zipped folders. I want to put those folders into separate lists depending on the files that are present within each zipped folder. For example, if one zipped folder contains a .CSV file I want to put it into a list called csvfiles = []. Or if the zipped folder contains a file with a .gdb extension, I want to put it into a gdbfiles = [] list. Here is a picture of the file structure I am working with for testing.

enter image description here

Here is what I have so far - it is far from being complete though:

gdbfiles = []
shpfiles = []
root_dirs = []  

for i in zipfiles:
    zip_f = ZipFile(i)
    for f in zip_f.namelist():
        zinfo = zip_f.getinfo(f)
        if zinfo.is_dir():
            r_dir = f.split('/')
            r_dir = r_dir[0]
            if r_dir not in root_dirs:
                root_dirs.append(r_dir)
    for d in root_dirs:
        if d.endswith(".gdb"):
            gdbfiles.append(os.path.join(root, d))
        else:
            shpfiles.append(os.path.join(root, d))

I am working on this with Python 3.6. Any code samples would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source