Monday, October 30, 2017

Function to Zip and UnZip the folder and files

Function fnZipFile(strSource,strTarget)
    fnZipFile = false
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set fso = CreateObject("Scripting.FileSystemObject")

    'write zip file header
    set file = fso.opentextfile(strTarget,ForWriting,True)
    file.write "PK" & chr(5) & chr(6) & string(18,chr(0))
    file.close
   
    'copy source file to zip file
    set shl = CreateObject("Shell.Application")
    shl.namespace(strTarget).copyhere(strSource)
    set shl = Nothing
    fnZipFile = True
End Function

Function fnUnZip(sUnfnZipFileName,sUnzipDestination)
Set oUnzipFSO = CreateObject("Scripting.FileSystemObject")
If (Not (oUnzipFSO.FolderExists(sUnzipDestination))) Then
oUnzipFSO.CreateFolder(sUnzipDestination)
End If
With CreateObject("Shell.Application")
.NameSpace(sUnzipDestination).Copyhere .NameSpace(sUnfnZipFileName).Items
End With
Set oUnzipFSO = Nothing
End Function

No comments:

Post a Comment