Saturday, June 19, 2010

Unzip a zip file - Lotus Script

How to unzip a zip file? unzipping of files should be done in the backgrouod. The script should not show any dialog box and should not ask for destination folder and any other details. We can't do these things using lotus script. Lotus script does not have function to do this. By using windows API functions in Lotus script we can achieve it.

strFile = "C:\4942.zip"
strDest = "c:\files"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strDest) Then
    objFSO.CreateFolder(strDest)
End If

UnZipFile strFile, strDest

Sub UnZipFile(strArchive, strDest)
    Set objApp = CreateObject( "Shell.Application" )

    Set objArchive = objApp.NameSpace(strArchive).Items()
    Set objDest = objApp.NameSpace(strDest)

    objDest.CopyHere objArchive
End Sub

3 comments:

  1. Daniel, just want to thank you for this beautiful little piece of code! It is EXACTLY what I need to solve my problem. I can't believe how simple it is, but I guess most things are simple when you have the knowledge, and clearly YOU HAVE THE KNOWLEDGE. Bernie...

    ReplyDelete
  2. Hi Daniel. Great code. I used the code to create a folder & unzip a file. I attached the file to a form. I then deleted the files & when I try to remove the folder either by using rmdir or manually I get an error saying that the folder is being used by another person or system. Could you help please?

    ReplyDelete
  3. Hi Daniel, Very useful code. Thanks!

    ReplyDelete