Connecting Tech Pros Worldwide Forums | Help | Site Map

Unzipping a file on upload in Ruby

Newbie
 
Join Date: Oct 2007
Posts: 19
#1: Feb 5 '09
Hello everyone,
I am uploading a zipped file where in which i need the unzipped file should get extracted to some target directory after uploading. I tried by using rubyzip gem,but its not working.Please help me how can i do this.


Regards,
amulyab

Expert
 
Join Date: May 2007
Posts: 213
#2: Feb 5 '09

re: Unzipping a file on upload in Ruby


Maybe ZipFileSystem or Archive::Tar::Minitar.
Newbie
 
Join Date: Oct 2007
Posts: 19
#3: Mar 24 '09

re: Unzipping a file on upload in Ruby


Hello all,
I got a method for uploading a zipped file and extract its folder and save in a directory.


Expand|Select|Wrap|Line Numbers
  1.  Zip::ZipFile.open(file_path) { |zip_file|
  2.      zip_file.each { |f|
  3.      f_path=File.join("destination_path", f.name)
  4.      FileUtils.mkdir_p(File.dirname(f_path))
  5.      zip_file.extract(f, f_path) unless File.exist?(f_path)
  6.    }
  7.   }
Hope it helps.Thanks
Reply