sophia
sophia

Reputation: 3

VB.Net Add to Existing Zip File

So I have a Zip file that is like the following: \server\test\test\Alphabet.zip

And the contents of the zip file are 3 text files:
Alphabet.zip
    -A.txt
    -B.txt
    -C.txt

 

Now in the same path, I have 3 more text files and few more files.
\server\test\test\D.txt
\server\test\test\E.txt
\server\test\test\F.txt
\server\test\test\image.jpg
\server\test\test\image2.jpg

 

I want to add the 3 text files to the existing zip using DotNetZip.  As I have to add hundreds of files, adding them file by file takes a lot of time. Getting a list and adding the list is a lot faster. But the problem I have is when I add the list of files to the zip, the folders of the directory are also created inside the zip as well and the 3 txt files are in the folder. I got like

Alphabet.zip
    -A.txt
    -B.txt
    -C.txt
    -\server\
         \test\
            \test\
                -D.txt
                -E.txt
                -F.txt

 

What I want is

Alphabet.zip
    -A.txt
    -B.txt
    -C.txt
    -D.txt
    -E.txt
    -F.txt

I used dotnetzip and the code is as follows

 

Dim path = \\server\test\test\
Dim txtfiles as New List(Of String)

Dim di As New IO.DirectoryInfo(path)
Dim filelist as IO.FileInfo() = di.GetFiles(di)

for each file in filelist
     If file.Extension = "*.txt" Then
     txtfiles.Add(file.FullName)
End If

Using zip As Ionic.Zip.ZipFile = ZipFile.Read(\\server\test\test\Alphabet.zip)
    zip.AddFiles(txtfiles)
    zip.Save()
End Using

Upvotes: 0

Views: 422

Answers (1)

sophia
sophia

Reputation: 3

It worked when I added the “” when adding the list if files to the zip file.

zip.AddFiles(txtfiles, “”)

Upvotes: 0

Related Questions