Extracting the extracted with python
Question: I have a zip file containing thousands of mixed .xml and .csv files. I used
the following to extract the zip file:

    
    
    import zipfile
    
    zip = zipfile.ZipFile(r'c:\my.zip')
    
    zip.extractall(r'c:\output')
    

Now I need to extract the thousands of individual zip files contained in the
'c:\output' folder. I am planning on concatenating just the .csv files into
one file. Thank you for the help!


Answer: Try this code :

    
    
    import zipfile , os
    
    zip = zipfile.ZipFile(r'c:/my.zip')
    
    zip.extractall(r'c:/output')
    
    filelist = []
    for name in zip.namelist():
        filelist.append(name)
    
    
    
    zip.close()
    for i in filelist:
    
    
        newzip = zipfile.ZipFile(r'c:/output/'+str(i))
        for file in newzip.namelist():
            if '.csv' in file :
                newzip.extract(file,r'c:/output/')
        newzip.close()
        os.remove(r'c:/output/'+str(i))
    

