Unzipping a file on upload in Ruby

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • divyakgowda
    New Member
    • Oct 2007
    • 19

    Unzipping a file on upload in Ruby

    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
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    Maybe ZipFileSystem or Archive::Tar::M initar.

    Comment

    • divyakgowda
      New Member
      • Oct 2007
      • 19

      #3
      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.


      Code:
       Zip::ZipFile.open(file_path) { |zip_file|
           zip_file.each { |f|
           f_path=File.join("destination_path", f.name)
           FileUtils.mkdir_p(File.dirname(f_path))
           zip_file.extract(f, f_path) unless File.exist?(f_path)
         }
        }
      Hope it helps.Thanks
      Last edited by eWish; Apr 28 '09, 12:58 PM. Reason: Please use the code tags

      Comment

      Working...