lib/real_zip.rb in real_zip-1.1.6 vs lib/real_zip.rb in real_zip-1.1.7

- old
+ new

@@ -62,54 +62,33 @@ first_dir = dir z.dir.mkdir(dir) unless z.file.exist? dir end hash = struct - # puts "hash => #{hash}" hash.each do |dir,file_arr| - - # puts "directory ======> #{dir}" - # puts "file_array ======> #{file_arr.to_s}" - new_files = files({dir => file_arr}) - # puts "new files ======> #{new_files.to_s}" new_files.each_with_index do |file, index| - # puts "file ======> #{file} index => #{index}" orignal_file_path = file_arr[index] - # puts "orignal_file_path ==========> #{orignal_file_path}" - - # unless File.file?(orignal_file_path) - # if dir.to_s == 'home' - # source = "#{orignal_file_path}" - # puts " Not a file #{source}" - # puts "directory =====> #{dir}" - # directory = source - - # Dir.foreach(source).each do | file_or_dir| - - # if File.file?(file_or_dir) - - # z.add(new_file_name, ) - # end - # end - - - - - # # binding.pry - # # - # else + if File.directory?(orignal_file_path) + puts "..... directory found ......" + source = "#{orignal_file_path}" + # directory_name = source.split('/').last + Dir.glob("#{source}**/*").reject {|fn| File.directory?(fn) }.each do |file| + string = File.open(file, 'r'){ |f| f.read } + destination_path = file.sub(source, '' ) + destination_path = "#{dir.to_s}/#{destination_path}" + puts "adding file #{destination_path} ..." + z.file.open(destination_path, "w") { |f| f.write string } + end + else + puts "..... File found ......" string = File.open(orignal_file_path, 'r'){ |f| f.read } file_name = file.split('/').last new_file_name = ( files( {dir => [ "#{file_name}" ] } ) ).first - # puts "file_name ========> #{file_name}" z.file.open(new_file_name, "w") { |f| f.write string } - # end - + end end - # binding.pry end - # binding.pry end end def struct given=file_structure given.is_a?(String) ? YAML.load(given) : given \ No newline at end of file