繁体   English   中英

zipfile.ZipFile仅提取一个文件夹

[英]zipfile.ZipFile only extracting one folder

我有这个代码

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()

zip文件正确下载zip文件保存在正确的位置,在super.zip内正确删除的目录中有12个目录,如果这12个目录是test.txt文件,则每个目录中都有12个目录。当我提取Super.zip时,它仅提取12个目录之一并且提取的目录为空。 可能是我需要以某种方式停止或关闭关闭程序吗? 并在提取的同时将其删除。 任何人都可以在这里说明我的错。 谢谢

好的,现在可以正常工作了。谢谢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