Unzipping directory structure with python

后端 未结 9 1667
闹比i
闹比i 2020-12-13 00:56

I have a zip file which contains the following directory structure:

dir1\\dir2\\dir3a
dir1\\dir2\\dir3b

I\'m trying to unzip it and maintai

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 01:26

    I know it may be a little late to say this but Jeff is right. It's as simple as:

    import os
    from zipfile import ZipFile as zip
    
    def extractAll(zipName):
        z = zip(zipName)
        for f in z.namelist():
            if f.endswith('/'):
                os.makedirs(f)
            else:
                z.extract(f)
    
    if __name__ == '__main__':
        zipList = ['one.zip', 'two.zip', 'three.zip']
        for zip in zipList:
            extractAll(zipName)
    

提交回复
热议问题