したがって、基本的には、pwe ファイルと pws ファイルを含む zip ファイルの束を作成しています。
次のコードは、2 つのファイル (pws と pwe) を含む orgname_org_member_orguser1.zip という名前の zip ファイルの束を生成します。
@successful_orgs.each do |org|
file = "#{RAILS_ROOT}/my-data/#{org[:location]}_#{org[:member]}_#{org[:username]}.zip"
generate_file(ups_file, org)
end
def generate_file(file, org)
zipfile = Zip::ZipFile.open(file, Zip::ZipFile::CREATE)
pwe_text, pws_text = MyGenerator.password
pwe_file = "#{RAILS_ROOT}/tmp/#{org[:location]}_#{org[:member]}.pwe"
pws_file = "#{RAILS_ROOT}/tmp/#{org[:location]}_#{org[:member]}.pws"
File.open(pwe_file, 'w') { |file| file.write(pwe_text) }
File.open(pws_file, 'w') { |file| file.write(pws_text) }
zipfile.add("#{org[:location]}_#{org[:member]}.pwe", pwe_file)
zipfile.add("#{org[:location]}_#{org[:member]}.pws", pws_file)
zipfile.close
File.delete(pwe_file)
File.delete(pws_file)
end
コードにやっていることをさせたい(zipファイルを作成し、指定されたパスに保存する)
しかし、上記に加えて、上記で作成したすべての zip ファイルを含む all.zip という別の zip ファイルも作成したいと考えています。
つまり、all.zip => file1.zip、file2.zip など
上記のコードにそのロジックを組み込む方法がわかりません。どんな助けでも大歓迎です。
編集:ディレクトリ内のすべてのファイルを検索して追加したくありません。上記のコードで作成された zip ファイルのみを追加したい。