wqweto / VszLib

7-zip VB6 Helper
GNU Lesser General Public License v3.0
42 stars 23 forks source link

Add From Folder #3

Open cyberzilla opened 3 years ago

cyberzilla commented 3 years ago

Is possible to add from folder @wqweto ?

i have try:

With New cVszArchive
        .AddFile App.Path & "\plugins\*.*"
        .Parameter("x") = 3 '-- CompressionLevel = Fast
        .CompressArchive App.Path & "\plugins.7z"
End With
MsgBox "pluginsx.7z created ok", vbExclamation

but not working

wqweto commented 3 years ago

AddFile method as the name implies can add a single file and there is no AddFolder method available but it is trivial to enum files in a folder and call AddFile for each one of them like this

Dim vElem As Variant

With New cVszArchive
        ' .AddFile App.Path & "\plugins\*.*"
        For Each vElem In CreateObject("Scripting.FileSystemObject").GetFolder(App.Path & "\plugins").Files
            .AddFile vElem.Path
        Next
        .Parameter("x") = 3 '-- CompressionLevel = Fast
        .CompressArchive App.Path & "\plugins.7z"
End With
MsgBox "pluginsx.7z created ok", vbExclamation

Another option is to implement your custom EnumFiles function similar in usage as the code above if you need to recursively enumerate files in all subfolders or filter on a wilcard mask or whatever your needs be.

Check out EnumFiles function in vbimg2pdf project for such helper function using built-in Dir function.

Check out pvEnumFiles function in ZipArchive project for a such helper function based on FindFirst/NextFile API functions.