Hallo,
Ich habe versucht den code aus dem beitrag
Zu adaptieren und um eine Pfadeingabe mittesl Save file Dialog erweitert doch irgenetwas mache ich Falsch da ich immer nur Lere Zip files erstelle ohne inhalt obwol im Ordner eindeutig inhalt verhanden ist
Mfg
Lusiphur
Ich habe versucht den code aus dem beitrag
Zu adaptieren und um eine Pfadeingabe mittesl Save file Dialog erweitert doch irgenetwas mache ich Falsch da ich immer nur Lere Zip files erstelle ohne inhalt obwol im Ordner eindeutig inhalt verhanden ist
Mfg
Lusiphur
Code:
string parentPath;
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "Backup Dateien | *.zip";
saveFileDialog1.DefaultExt = "*.zip";
saveFileDialog1.ShowDialog();
string path3=saveFileDialog1.FileName.ToString();
ZipOutputStream s = new ZipOutputStream(File.Create(path3));
s.SetLevel(1);
DirectoryInfo maindir = new DirectoryInfo("C:\\Projekt\\");
parentPath = maindir.Parent.FullName + @"\";
MessageBox.Show(parentPath);
GoSubdirs(ref s, statics.Projektpfad);
s.Close();
}
private void GoSubdirs(ref ZipOutputStream s, string path)
{
DirectoryInfo dir = new DirectoryInfo(path);
foreach (DirectoryInfo subdir in dir.GetDirectories())
{
GoSubdirs(ref s, subdir.FullName);
}
foreach (FileInfo fi in dir.GetFiles())
{
FileStream fs = File.OpenRead(fi.FullName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(dir.FullName.Replace(parentPath, "") + "/" + fi.Name);
entry.Size = fs.Length;
fs.Close();
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
}