DotNetZip Library - Home
DotNetZip は Microsoft Public License の ZIP ライブラリ プロジェクト。
試しに C# からコマンドラインでパスワード付きZIPを作成するサンプルプログラムを書いてみた。
using System; using System.IO; using Ionic.Utils.Zip; namespace AppTest { class Program { static void Main(string[] args) { string filePath = null; string zipfile = null; string password = null; for (int i = 0; i < args.Length; i++) { if (args[i] == “-p”) { password = args[++i]; } else if (filePath == null) { filePath = args[i]; } else { zipfile = args[i]; } } if (filePath == null || zipfile == null || !File.Exists(filePath)) { if (args.Length != 2) { Console.WriteLine(“Usage WhiteMole.exe [-p password] file zipfile”); } return; } try { zipAtEncrypt(filePath, zipfile, password); } catch (ZipException) { Console.WriteLine(“Failed to compress " + filePath); } } private static void zipAtEncrypt(string filePath, string zipfile, string password) { using (ZipFile zip = new ZipFile(zipfile)) { if (password != null) zip.Password = password; zip.AddFile(filePath); zip.Save(); } } } }
...