現在、ユーザーが最大6つのディレクトリを入力できるようにするソフトウェアを作成しています。各ディレクトリは文字列として(配列内に)保存され、ループは配列とnullではないものをすべてチェックすることを目的としています。ディレクトリが割り当てられている場合は、独自のアーカイブに圧縮されることを意図しています。これは私がこれまでに持っているコードです。
private void ZipIt()
{
int nxtFileNum = 0;
string Destination = @"C:\tmpZip" + nxtFileNum + ".zip";
// Check all fields, check if empty, if not save to Selection array
// Seems a inefficient - Possibly loop through Text box control type and collect?
if (String.IsNullOrEmpty(tboxSelect1.Text) == false) { BckupArray[0] = tboxSelect1.Text; };
if (String.IsNullOrEmpty(tboxSelect2.Text) == false) { BckupArray[1] = tboxSelect2.Text; };
if (String.IsNullOrEmpty(tboxSelect3.Text) == false) { BckupArray[2] = tboxSelect3.Text; };
if (String.IsNullOrEmpty(tboxSelect4.Text) == false) { BckupArray[3] = tboxSelect4.Text; };
if (String.IsNullOrEmpty(tboxSelect5.Text) == false) { BckupArray[4] = tboxSelect5.Text; };
if (String.IsNullOrEmpty(tboxSelect6.Text) == false) { BckupArray[5] = tboxSelect6.Text; };
// Create a new ZipFile entity and then loop through each array member, checking if
// it has an assigned value, if so compress it, if not, skip it.
using (ZipFile ZipIt = new ZipFile())
{
nxtFileNum++;
foreach (String q in BckupArray)
{
if (q != null)
{
ZipIt.AddDirectory(q);
ZipIt.Comment = "This archive was created at " + System.DateTime.Now.ToString("G");
ZipIt.Save(Destination);
}
}
}
}
これを実行しようとしているのは、場所を指定された最初のユーザーを tmpZip0.7z に保存し、2 番目のユーザーを tmpZip1.7z に保存することですが、現時点では、各ディレクトリを tmpZip0.zip に追加するだけです。
また、補足として、アーカイブするように選択されたディレクトリの後に各アーカイブに名前を付けるにはどうすればよいですか?
現在 DotNetZip (Ionic.Zip) dll を使用しています。
十分な情報を提供したことを願っています。