ziplib 解压目录

ziplib 解压目录

from zipfile    import *
   
source_zip="c:\\pbd\\20070118-140549.zip"
target_dir="c:\\pbd\\"
myzip=ZipFile(source_zip)
myfilelist=myzip.namelist()
count_file=len(myfilelist)
i=0

for i in xrange(0,count_file):
    #print target_dir
    print myfilelist[i]
    #f_handle=open(target_dir+myfilelist[i],"wb")
    #f_handle.write(myzip.read(myfilelist[i]))
    #f_handle.close()
myzip.close()

问题压缩包解开后的路径为什么是这样?要手工替换才能解压吗?
20070118-140549/basa_ds.pbd
20070118-140549/basa_dw.pbd
20070118-140549/basa_win.pbd
20070118-140549/ctna_ds.pbd
20070118-140549/ctna_dw.pbd
20070118-140549/ctna_oth.pbd
20070118-140549/ctna_win.pbd
20070118-140549/ebda_ds.pbd
20070118-140549/ebda_dw.pbd
20070118-140549/ebda_oth.pbd
20070118-140549/ebda_win.pbd
20070118-140549/ecda_dw.pbd
20070118-140549/ecda_oth.pbd
20070118-140549/ecda_win.pbd
20070118-140549/ecdb_win.pbd
20070118-140549/ecd_rpt.pbd
20070118-140549/edia_ds.pbd
20070118-140549/edia_dw.pbd
20070118-140549/edia_oth.pbd
20070118-140549/edia_win.pbd
20070118-140549/edib_ds.pbd
20070118-140549/edib_oth.pbd
20070118-140549/edib_win.pbd
20070118-140549/freightsettlea_ds.pbd
20070118-140549/freightsettlea_dw.pbd
20070118-140549/freightsettlea_dw_in.pbd
20070118-140549/freightsettlea_oth.pbd
20070118-140549/freightsettlea_win.pbd
20070118-140549/freightsettlea_win_in.pbd
20070118-140549/freightsettleb_dw_in.pbd
20070118-140549/ibda_ds.pbd
20070118-140549/ibda_dw.pbd
20070118-140549/ibda_oth.pbd
20070118-140549/ibda_win.pbd
20070118-140549/icda_ds.pbd
20070118-140549/icda_dw.pbd
20070118-140549/icda_oth.pbd
20070118-140549/icda_win.pbd
20070118-140549/manifest_ds.pbd
20070118-140549/publica_ds.pbd
20070118-140549/publica_dw.pbd
20070118-140549/publica_oth.pbd
20070118-140549/publica_win.pbd
20070118-140549/voucher_u8.pbd
20070118-140549/voyagesettlea_ds.pbd
20070118-140549/voyagesettlea_dw.pbd
20070118-140549/voyagesettlea_oth.pbd
20070118-140549/voyagesettlea_rpt.pbd
20070118-140549/voyagesettlea_win.pbd
20070118-140549/vsla_ds.pbd
20070118-140549/vsla_dw.pbd
20070118-140549/vsla_oth.pbd
20070118-140549/vsla_win.pbd
20070118-140549/zashistory.pbd
挺正常啊。你用zip工具看一看它的目录结构不就知道了。


QUOTE:
原帖由 limodou 于 2007-1-23 11:01 发表
挺正常啊。你用zip工具看一看它的目录结构不就知道了。

Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\image\unzip.py", line 16, in ?
    f_handle=open(file_path,"wb")
IOError: [Errno 2] No such file or directory: 'c:\\pbd\\20070118-140549\\basa_ds.pbd'
Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\image\unzip.py", line 12, in ?
    f_handle=open(file_path,"wb")
IOError: [Errno 2] No such file or directory: 'c:\\pbd\\20070118-140549/basa_ds.pbd'

是不是在解压前要选建立这些文件?
不是文件,而是目录20070118-140549,我想这个目录可能你还没有创建。


QUOTE:
原帖由 lvxinzhi 于 2007-1-23 11:07 发表


Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
...

解决了,自己不能建立目录
我以前写过一个zip文件处理的小程序,可以在 http://wiki.woodpecker.org.cn/mo ... amp;target=zfile.py
找到。可以单独运行,也可以作为模块来使用。