Problem while trying to extract a directory from a zipfile.

Discussion in 'Python' started by ralobao, Dec 8, 2004.

  1. ralobao

    ralobao Guest

    I have this code:

    try:
    file = zipfile.ZipFile(nome_arquivo)
    Gauge.start() #inicia o Gauge
    for element in file.namelist():
    try:
    newFile = open(diretorio + element,"wb")
    except:
    newFile = open(diretorio + element + '/',"w")
    # Gauge
    percent = percent + 10
    Gauge.update(percent)
    Gauge.set_text("Extraindo" + element)
    # Extrai
    newFile.write(file.read(element))
    newFile.close()

    But when i try to extract an zipfile with a directory in it the code
    returns me an IOErro exception: "It is a directory"

    Please how can i solve it ?
     
    ralobao, Dec 8, 2004
    #1
    1. Advertising

  2. ralobao wrote:
    > I have this code:
    >
    > try:
    > file = zipfile.ZipFile(nome_arquivo)
    > Gauge.start() #inicia o Gauge
    > for element in file.namelist():
    > try:
    > newFile = open(diretorio + element,"wb")
    > except:
    > newFile = open(diretorio + element + '/',"w")
    > # Gauge
    > percent = percent + 10
    > Gauge.update(percent)
    > Gauge.set_text("Extraindo" + element)
    > # Extrai
    > newFile.write(file.read(element))
    > newFile.close()
    >
    > But when i try to extract an zipfile with a directory in it the code
    > returns me an IOErro exception: "It is a directory"
    >
    > Please how can i solve it ?


    You need to create any directories yourself. Maybe
    the recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252508
    gives you some ideas on how.

    HTH

    --
    Vincent Wehren
     
    vincent wehren, Dec 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ^CrazyCoder^
    Replies:
    3
    Views:
    7,316
    Terrence Benade
    Sep 15, 2003
  2. Tung Wai Yip

    add empty directory using zipfile?

    Tung Wai Yip, Jun 25, 2003, in forum: Python
    Replies:
    6
    Views:
    5,375
    Tung Wai Yip
    Jun 26, 2003
  3. Bulba!
    Replies:
    2
    Views:
    411
    Bulba!
    Dec 9, 2004
  4. Martin
    Replies:
    5
    Views:
    592
    Stefan Behnel
    Jul 10, 2007
  5. Ingmar Hamer

    ZipFile.extract overwrite option

    Ingmar Hamer, Oct 8, 2009, in forum: Ruby
    Replies:
    2
    Views:
    698
    Ingmar Hamer
    Oct 9, 2009
Loading...

Share This Page