ZipFile.extract overwrite option

Discussion in 'Ruby' started by Ingmar Hamer, Oct 8, 2009.

  1. Ingmar Hamer

    Ingmar Hamer Guest

    Hi

    I'm trying to extract a Zipfile using the ZipFile Class.
    According to the docs,
    http://rubyzip.sourceforge.net/classes/Zip/ZipFile.html#M000150"
    the extract method takes a third param to specify the behaviour if a
    file already exists.

    However if I try to use that param I get a "wrong number of arguments (3
    for 2)" error.


    My code:

    =====================================================
    require 'fileutils'
    require 'zip/zip'
    require 'zip/zipfilesystem'

    def unzip(file,destination)
    Zip::ZipFile.open(file) { |zip_file|
    zip_file.each { |f|
    f_path=File.join(destination, f.name)
    FileUtils.mkdir_p(File.dirname(f_path))
    zip_file.extract(f, f_path, proc { true })
    }
    }
    end
    =====================================================


    What am I doing wrong?
    --
    Posted via http://www.ruby-forum.com/.
    Ingmar Hamer, Oct 8, 2009
    #1
    1. Advertising

  2. Ingmar Hamer

    Tom Stuart Guest

    2009/10/8 Ingmar Hamer <>:
    > Hi
    >
    > I'm trying to extract a Zipfile using the ZipFile Class.
    > According to the docs,
    > http://rubyzip.sourceforge.net/classes/Zip/ZipFile.html#M000150"
    > the extract method takes a third param to specify the behaviour if a
    > file already exists.
    >
    > However if I try to use that param I get a "wrong number of arguments (3
    > for 2)" error.
    >
    >
    > My code:
    >
    > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D
    > require 'fileutils'
    > require 'zip/zip'
    > require 'zip/zipfilesystem'
    >
    > def unzip(file,destination)
    > =A0 =A0Zip::ZipFile.open(file) { |zip_file|
    > =A0 =A0zip_file.each { |f|
    > =A0 =A0f_path=3DFile.join(destination, f.name)
    > =A0 =A0FileUtils.mkdir_p(File.dirname(f_path))
    > =A0 =A0zip_file.extract(f, f_path, proc { true })
    > =A0 }
    > =A0}
    > end
    > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
    =3D=3D=3D=3D
    >
    >
    > What am I doing wrong?


    Zipfile#extract's third argument is prefixed with &, which means it
    expects to be called like so:

    ...
    zip_file.extract(f, f_path) { true }
    ...
    Tom Stuart, Oct 8, 2009
    #2
    1. Advertising

  3. Ingmar Hamer

    Ingmar Hamer Guest

    Ingmar Hamer, Oct 9, 2009
    #3
    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. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    714
    GianGuz
    Dec 21, 2004
  2. Ramaraj  M Bijur
    Replies:
    15
    Views:
    864
    CBFalconer
    Apr 20, 2004
  3. ralobao
    Replies:
    1
    Views:
    295
    vincent wehren
    Dec 8, 2004
  4. Faik Uygur

    umask option for tarfile extract

    Faik Uygur, Jun 15, 2006, in forum: Python
    Replies:
    0
    Views:
    380
    Faik Uygur
    Jun 15, 2006
  5. Cas
    Replies:
    5
    Views:
    790
    Kevin Jones
    Aug 28, 2006
Loading...

Share This Page