unzip process exception. dunno why

Discussion in 'Ruby' started by Junkone, Sep 11, 2011.

  1. Junkone

    Junkone Guest

    i get an error Got exception can't convert Tempfile into String. This
    happens right at the line Zip::ZipFile.open(source) do |zipfile|
    I have passed the downloaded file block to the source variable.
    any help is appreciated.
    The intend is to download the http://www.dtniq.com/product/mktsymbols_v2.zip
    and unzip it to teh temp folder.


    require 'rubygems'
    require 'open-uri'
    require 'zip/zipfilesystem'
    # source should be a zip file.
    # target should be a directory to output the contents to.
    def unzip_file(source, target)
    # Create the target directory.
    # We'll ignore the error scenario where
    begin
    Dir.mkdir(target) unless File.exists? target
    end
    puts "going to open the zip file"
    Zip::ZipFile.open(source) do |zipfile|
    dir = zipfile.dir
    puts dir.to_s
    dir.entries('.').each do |entry|
    puts "#{target}/#{entry}"
    zipfile.extract(entry, "#{target}/#{entry}")
    end
    end

    rescue Zip::ZipDestinationFileExistsError => ex
    puts "ignore error "
    # I'm going to ignore this and just overwrite the files.
    rescue => ex
    puts "Got exception " + ex
    end





    url = 'http://www.dtniq.com/product/mktsymbols_v2.zip'
    open(url, 'r') do |fo|
    puts "unzipfile "
    unzip_file(fo, "c:\\temp11\\")
    fo.print open('http://wordpress.org/latest.zip').read
    end
    Junkone, Sep 11, 2011
    #1
    1. Advertising

  2. Junkone

    Chris Hulan Guest

    Chris Hulan, Sep 12, 2011
    #2
    1. Advertising

  3. Junkone

    Junkone Guest

    On Sep 12, 9:25 am, Chris Hulan <> wrote:
    >  Zip::ZipFile.open(source) - source should be the name of the zip file (seehttp://rubyzip.sourceforge.net/classes/Zip/ZipFile.html#M000143)
    >
    > You have already opened the file and are passing in the file object
    >
    > cheers


    you mean i should only pass the file name and path of the zipfile.
    Junkone, Sep 13, 2011
    #3
  4. Junkone

    Chris Hulan Guest

    Yes
    Chris Hulan, Sep 13, 2011
    #4
    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. Macroman
    Replies:
    1
    Views:
    412
    Macroman
    Feb 18, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,681
    Smokey Grindel
    Dec 2, 2006
  3. Rocky Zhou
    Replies:
    0
    Views:
    553
    Rocky Zhou
    Apr 2, 2007
  4. Anarki
    Replies:
    0
    Views:
    257
    Anarki
    Oct 31, 2008
  5. Junkone

    yaml error. dunno why

    Junkone, Nov 10, 2007, in forum: Ruby
    Replies:
    2
    Views:
    128
    Joel VanderWerf
    Nov 10, 2007
Loading...

Share This Page