0

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
sophia
  • 3
  • 4
  • 1
    You should have a look through the documentation; maybe the [AddFiles Method (fileNames, directoryPathInArchive)](https://documentation.help/DotNetZip/007fac8a-e77e-f558-41e4-572d47946c33.htm) is what you're looking for. "Adds a set of files to the ZipFile, using the specified directory path in the archive.... Passing the empty string ("") will insert the item at the root path within the archive." – Andrew Morton Apr 26 '23 at 12:25

1 Answers1

0

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

zip.AddFiles(txtfiles, “”)
sophia
  • 3
  • 4