简体   繁体   English

zipfile.ZipFile仅提取一个文件夹

[英]zipfile.ZipFile only extracting one folder

I have this code 我有这个代码

def downloadupdate():
    url = 'http://myurl.com/o/test/list.zip'
    destination = xbmc.translatePath('special://home/userdata/addon_data/iupdatefix/Super.zip')
    urllib.urlretrieve(url,destination)
    time.sleep(40)

    updatezip = xbmc.translatePath('special://home/userdata/addon_data/iupdatefix/Super.zip')
    extractupdate = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.test/')
    oldfav = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.test/test')
    yeszip = os.path.exists(updatezip)
    shutil.rmtree(oldfav, ignore_errors=False)
    time.sleep(10)
    if yeszip:
        gh = open(updatezip, 'rb')
        zp = zipfile.ZipFile(gh)
        for name in zp.namelist():
            zp.extract(name, extractupdate)
            gh.close()
            time.sleep(3)
    else:
        xbmc.executebuiltin("Notification(some text, sometext,()")

downloadupdate()

The zip file downloads correctly the zip file saves in the correct location the deletes correctly inside super.zip there are 12 directories and in each if these twelve directories is test.txt file When I extract Super.zip it only extracts one of the twelve directories and that extracted directory is empty. zip文件正确下载zip文件保存在正确的位置,在super.zip内正确删除的目录中有12个目录,如果这12个目录是test.txt文件,则每个目录中都有12个目录。当我提取Super.zip时,它仅提取12个目录之一并且提取的目录为空。 Could it be that I need to somehow stop or close the shutil process? 可能是我需要以某种方式停止或关闭关闭程序吗? and as its extracting, its being erased at the same time by shutil? 并在提取的同时将其删除。 Could anyone please shed some light on my fault here please. 任何人都可以在这里说明我的错。 Thankyou 谢谢

ok so it is now working Thankyou david a GIRISH 好的,现在可以正常工作了。谢谢david一个GIRISH

def downloadupdate():
    url = 'http://myurl.com/o/test/list.zip'
    destination = xbmc.translatePath('special://home/userdata/addon_data/iupdatefix/Super.zip')
    urllib.urlretrieve(url,destination)
    time.sleep(40)

    updatezip = xbmc.translatePath('special://home/userdata/addon_data/iupdatefix/Super.zip')
    extractupdate = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.test/')
    oldfav = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.test/test')
    yeszip = os.path.exists(updatezip)
    shutil.rmtree(oldfav, ignore_errors=False)
    time.sleep(10)
    if yeszip:
        gh = open(updatezip, 'rb')
        zp = zipfile.ZipFile(gh)
        zp.extractall(extractupdate)
        gh.close()
        time.sleep(3)
    else:
        xbmc.executebuiltin("Notification(some text, sometext,()")

downloadupdate()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM