2012-03-12 25 views
0

Ruby(1.9.3)を使用する私はzipアーカイブ内の1つのファイルを置き換える必要があります。zipアーカイブ内のファイルを置換する

状況は次のとおりです。私は〜1000のzipアーカイブを更新する必要があります。特に、それぞれのファイルの1つを置き換える必要があります。アーカイブはすべて同じ構造です。 RubyのためのRubyやライブラリ/ gemが「このzipアーカイブ内のファイルをファイルシステム上のこのファイルで置き換える」と言うだけの素早く汚い方法はありますか?

私はその間に私自身の解決策を取ります。

+0

を見てみましょうあまりにもbashの許容ですか? – Reactormonk

答えて

1

ruby​​から呼び出されたzipコマンドを使用できます。これはおそらく最適な解決方法です。ジップマンページからzip manpage

 -d 
    --delete 
      Remove (delete) entries from a zip archive. For example: 

       zip -d foo foo/tom/junk foo/harry/\* \*.o 

      will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any path). Note that shell path‐ 
      name expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling zip to match on the contents of the zip archive instead of the 
      contents of the current directory. (The backslashes are not used on MSDOS-based platforms.) Can also use quotes to escape the asterisks as in 

       zip -d foo foo/tom/junk "foo/harry/*" "*.o" 

      Not escaping the asterisks on a system where the shell expands wildcards could result in the asterisks being converted to a list of files in the current 
      directory and that list used to delete entries from the archive. 

      Under MSDOS, -d is case sensitive when it matches names in the zip archive. This requires that file names be entered in upper case if they were zipped by 
      PKZIP on an MSDOS system. (We considered making this case insensitive on systems where paths were case insensitive, but it is possible the archive came from 
      a system where case does matter and the archive could include both Bar and bar as separate files in the archive.) But see the new option -ic to ignore case 
      in the archive. 

あなたは純粋なルビーのソリューションをしたい場合はZipFileSystem

+0

これはうまくいくでしょう。ありがとう。 –

0

Zip::ZipFile有望です。 zipアーカイブにファイルを削除して追加する方法があるようだ。

関連する問題