jaime-olivares / zipstorer

A Pure C# Class to Store Files in Zip
MIT License
183 stars 63 forks source link

Added AddDirectory fuction #32

Closed Toxaris-NL closed 5 years ago

Toxaris-NL commented 5 years ago

I have added an AddDirectory function. No idea if this was there before. I tried to add it quite some time ago, but something went wrong...

benchen71 commented 5 years ago

If it helps, I converted this function into vb for the file zipstorer.vb and have been using it successfully for a while now:

''' <summary>
''' Add full contents of a directory into the Zip storage
''' </summary>
''' <param name="_method">Compression method</param>
''' <param name="_pathname">Full path of directory to add to Zip storage</param>
''' <param name="_pathnameInZip">Path name as desired in Zip directory</param>
''' <param name="_comment">Comment for stored directory</param>
Public Sub AddDirectory(ByVal _method As Compression, ByVal _pathname As String, ByVal _pathnameInZip As String, ByVal _comment As String)
    If Access = FileAccess.Read Then
        Throw New InvalidOperationException("Writing is not allowed")
    End If

    Dim foldername As String
    Dim pos As Integer = _pathname.LastIndexOf(Path.DirectorySeparatorChar)
    If pos >= 0 Then
        foldername = _pathname.Remove(0, pos + 1)
    Else
        foldername = _pathname
    End If

    If _pathnameInZip IsNot Nothing AndAlso _pathnameInZip <> "" Then
        foldername = _pathnameInZip & foldername
    End If

    If Not foldername.EndsWith("/") Then
        foldername = foldername & "/"
    End If

    ' Process the list of files found in the directory.
    Dim fileEntries As String() = Directory.GetFiles(_pathname)
    For Each fileName As String In fileEntries
        AddFile(_method, fileName, foldername & Path.GetFileName(fileName), "")
    Next

    ' Recurse into subdirectories of this directory.
    Dim subdirectoryEntries As String() = Directory.GetDirectories(_pathname)
    For Each subdirectory As String In subdirectoryEntries
        AddDirectory(_method, subdirectory, foldername, "")
    Next
End Sub
jaime-olivares commented 5 years ago

Hi @Toxaris-NL I see there are a lot of non-functional changes in this PR. Please remove all the formatting changes.

Toxaris-NL commented 5 years ago

I have created another pull request which is much cleaner. This one can be closed and ignored.