0 votes
by (120 points)
edited by

The ZIP-files that are created using Rebex ZIP contains a rootfolder by the name 0, 1 or 2.

Why is this rootfolder created and how can it be avoided?

I use FileSet.

Using archive As New ZipArchive(Path.Combine(sProjectPath, project.GetZipName), Rebex.IO.Compression.ArchiveOpenMode.CreateNew)
    Dim fileSet As New Rebex.IO.FileSet(project.LocalPath)
    For Each include As String In project.Includes
        fileSet.Include(include, TraversalMode.MatchFilesDeep)
    For Each exclude As String In project.Excludes
    Dim result As ArchiveOperationResult = archive.Add(fileSet, TraversalMode.MatchFilesShallow, TransferMethod.Copy, ActionOnExistingFiles.OverwriteAll)
End Using

My project class looks like this

Public Class Project

    Public Property Type() As String

    Public Property Name() As String

    Public Property LocalPath() As String

    Public Property SubDirs() As Boolean

        XmlArrayItem(GetType(String), ElementName:="include")
    Public Includes As New List(Of String)

        XmlArrayItem(GetType(String), ElementName:="exclude")
    Public Excludes As New List(Of String)

    Public Property Enabled() As Boolean

    Public Function GetZipName() As String
        Return Me.Type().Replace(" ", "_") + "_" + Me.Name().Replace(" ", "_") + "_" + Date.Now.ToString("yyyyMMddHHmmss") + ".zip"
    End Function

End Class

The created zip file can be seen here:

Applies to: Rebex ZIP

2 Answers

0 votes
by (69.1k points)

Can you please post here your source code which uses ZipArchive and FileSet objects?

The ZipArchive names folders according to names of source folders - there are no hardcoded values such as name 0, 1 or 2.

Is it also possible for you to share source ZIP file (if any) and produced ZIP files which contains 0, 1, 2 root folders?
Or at least some image which shows the problem?
I am not sure, whether I understand the problem correctly.

Thank you.

by (120 points)
I have added sourcecode and an example zip-file to my question.
0 votes
by (69.1k points)

Thank you for the code. I found that the problem is in your code.
Actually, it is caused by "unhandy" tolerance of VB.NET which allows to pass nonstring variables to string parameters. Your code wouldn't be compiled if written in C#.

Please see declarations of the Add method with FileSet argument:

  1. Add(FileSet set)
  2. Add(FileSet set, string archiveDirectoryPath)
  3. Add(FileSet set, string archiveDirectoryPath, TransferMethod transferMethod, ActionOnExistingFiles defaultActionOnExistingFiles)

You used this:
archive.Add(fileSet, TraversalMode.MatchFilesShallow, TransferMethod.Copy, ActionOnExistingFiles.OverwriteAll)

Because of VB.NET, second parameter was implicitly cast to string in runtime and third method was used. In case of TraversalMode.MatchFilesShallow a string "2" was passed (which leads to creation of root folder "2").

The correct solution is to call the method like this:
archive.Add(fileSet, "/", TransferMethod.Copy, ActionOnExistingFiles.OverwriteAll)

by (120 points)
Worked Perfect :-)