Unzip zip files in folders and subfolders with python

后端 未结 3 626
一生所求
一生所求 2020-12-09 23:21

I try to unzip 150 zip files. All the zip files as different names, and they all spread in one big folder that divided to a lot of sub folders and sub sub folders.i want to

3条回答
  •  旧巷少年郎
    2020-12-09 23:32

    To unzip all the files into a temporary folder (Ubuntu)

    import tempfile
    import zipfile
    
    tmpdirname = tempfile.mkdtemp()
    
    zf = zipfile.ZipFile('/path/to/zipfile.zip')
    
    for fn in zf.namelist():
        temp_file = tmpdirname+"/"+fn
        #print(temp_file)
    
        f = open(temp_file, 'w')
        f.write(zf.read(fn).decode('utf-8'))
        f.close()
    

提交回复
热议问题