tags:

views:

81

answers:

2

Hi,

I'm trying to use RubyZip to package up some files. At the moment I have a method which happily zips on particular directory and sub-directories.

def zip_directory(zipfile)
 Dir["#{@directory_to_zip}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
  file_name = file_path.sub(@directory_to_zip+'/','');
  zipfile.add(file_name, file_path)
 end
end

However, I want to include a file from a completely different folder. I have a the following method to solve this:

def zip_additional(zipfile)
 additional_files.reject{|f| reject_file(f)}.each do |file_path|
  file_name = file_path.split('\\').last
  zipfile.add(file_name, file_path)
 end
end

While the file is added, it also copies the directory structure instead of placing the file at the root of the folder. This is really annoying and makes it more difficult to work with.

How can I get around this?

Thanks

Ben

+1  A: 

there is setting to include (or exclude) the full path for zip libraries, check that setting

dusoft
I can't seem to see anything in the rdoc - http://rubyzip.sourceforge.net/
Ben Hall
i am not sure about rubyzip, but i think that's the problem. standard zip libraries have this setting (include full path), maybe this article will be of any help?:http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/there is note below the code regarding how the path is created
dusoft
A: 

Turns out it was because the filename had the pull path in. My split didn't work as the path used a / instead of a . With the path removed from the filename it just worked.

Ben Hall