ZipFile.extract overwrite option

I

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:

=====================================================
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?
 
T

Tom Stuart

2009/10/8 Ingmar Hamer said:
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 }
...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top