Alexander Schuc
crazy-weasel
Hi.
Mit einem kleinen Snippet würden wir uns leichter tun beim Beantworten der Frage.
Mit einem kleinen Snippet würden wir uns leichter tun beim Beantworten der Frage.
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
Imports ICSharpCode.SharpZipLib.Zip
Imports ICSharpCode.SharpZipLib.Core
Imports System.IO
Dim parentPath As String
Private Sub btnZip_Click() 'object sender, System.EventArgs e)
Dim s As New ZipOutputStream(File.Create(TextBox2.Text))
s.SetLevel(1)
Dim maindir As New DirectoryInfo(TextBox1.Text)
parentPath = maindir.Parent.FullName + "\"
MessageBox.Show(parentPath)
GoSubdirs(s, TextBox1.Text)
s.Close()
End Sub
Private Sub GoSubdirs(ByVal s As ZipOutputStream, ByVal path As String)
Dim Dir As New DirectoryInfo(path)
For Each subdir In Dir.GetDirectories()
GoSubdirs(s, subdir.FullName)
Next
Dim fi As FileInfo
For Each fi In Dir.GetFiles()
Dim fs As FileStream = File.OpenRead(fi.FullName)
Dim buffer(fs.Length) As Byte
fs.Read(Buffer, 0, Buffer.Length)
Dim entry As New ZipEntry(Dir.FullName.Replace(parentPath, "") + "/" + fi.Name)
entry.Size = fs.Length
fs.Close()
s.PutNextEntry(entry)
s.Write(Buffer, 0, Buffer.Length)
Next
End Sub
Code:Imports ICSharpCode.SharpZipLib.Zip Imports ICSharpCode.SharpZipLib.Core Imports System.IO Dim parentPath As String Private Sub btnZip_Click() 'object sender, System.EventArgs e) Dim s As New ZipOutputStream(File.Create(TextBox2.Text)) s.SetLevel(1) Dim maindir As New DirectoryInfo(TextBox1.Text) parentPath = maindir.Parent.FullName + "\" MessageBox.Show(parentPath) GoSubdirs(s, TextBox1.Text) s.Close() End Sub Private Sub GoSubdirs(ByVal s As ZipOutputStream, ByVal path As String) Dim Dir As New DirectoryInfo(path) For Each subdir In Dir.GetDirectories() GoSubdirs(s, subdir.FullName) Next Dim fi As FileInfo For Each fi In Dir.GetFiles() Dim fs As FileStream = File.OpenRead(fi.FullName) Dim buffer(fs.Length) As Byte fs.Read(Buffer, 0, Buffer.Length) Dim entry As New ZipEntry(Dir.FullName.Replace(parentPath, "") + "/" + fi.Name) entry.Size = fs.Length fs.Close() s.PutNextEntry(entry) s.Write(Buffer, 0, Buffer.Length) Next End Sub
size was 167405, but I expected 167404