J
Junkone
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
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