Unzip all files and directories from a subfolder

半城伤御伤魂 提交于 2020-01-16 18:46:07

问题


My first post here.

I need to create a Python script that can extract the sub-folder content of a .zip file into a specified directory and I can't find a way to do this.

More exactly I'm upgrading daily the Blender_2.8 build from here: https://builder.blender.org/download/blender-2.80-741641f4c3b8-win64.zip

The problem is that every day the name of the folder inside the .zip file it is changing. I need to extract only the sub-folder content without the root folder.

I do have a somehow working solution, I just don't know hot to select ONLY the sub-folder content and not the whole folder inside the archive.

from zipfile import ZipFile

def main():

    print('Extract all files in ZIP to different directory')

    # Create a ZipFile Object and load sample.zip in it
    with ZipFile('b.zip', 'r') as zipObj:
       # Extract all the contents of zip file in different directory
       zipObj.extractall('C:\Programe\Blender_2.80')

if __name__ == '__main__':
   main()

Basically I need to get rid of the "blender-2.80.0-git.741641f4c3b8-windows64" folder and extract only his subfolders and files.

Also will be great if possible to write some code to download automatically the 64bit Windows build from the net instead of opening the browser and doing so manually.

Best regards.

来源:https://stackoverflow.com/questions/56645077/unzip-all-files-and-directories-from-a-subfolder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!