Forum Discussion
TanyaYatskovska
Alumni
13 years agoHi Tony,
Thanks for your example. I've formatted it if you don't mind:
'=================================
' Function: ExtractCompressedFiles(ByVal sSourceFile as STRING, ByVal sTargetDir as STRING) as BOOLEAN ' ' DESCRIPTION: ' This function extracts all files from a compressed "folder" (ZIP, CAB, etc.) using the Windows Shell ' Folders' CopyHere method (http://msdn2.microsoft.com/en-us/library/ms723207.aspx). All files and folders ' will be extracted from the ZIP file. A progress bar will be displayed. ' ' SCOPE: Public ' PARAMETERS: STRING sSourceFile fully qualified path of the compressed file ' STRING sTargetDir fully qualified path of the destination folder ' RETURNS: BOOLEAN TRUE = compressed file successfully extracted ' FALSE = compressed file could not be extracted ' ERRORS: Error message posted in results log(s) if specified compressed file does not exist. ' REVISION HISTORY: ' 09/09/06 A. Mrozinski Created.
'=================================
Public Function ExtractCompressedFiles(ByVal sSourceFile, ByVal sTargetDir)
Dim oFS, oShell, oSource, oTarget
ExtractCompressedFiles = FALSE
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sSourceFile) Then
If NOT oFS.FolderExists(sTargetDir) Then
oFS.CreateFolder(sTargetDir) ' create it and return TRUE
If NOT oFS.FolderExists(sTargetDir) Then
LogFail "ExtractCompressedFiles", "Specified target directory " & sTargetDir & " could not be created."
Set oFS = Nothing
Exit Function
End If
End If ' Create the required Shell objects
Set oShell = CreateObject("Shell.Application") ' Create a reference to the files and folders in the compressed file
Set oSource = oShell.NameSpace(sSourceFile).Items() ' Create a reference to the target folder
Set oTarget = oShell.NameSpace(sTargetDir)
' These are the pertinent CopyHere options, according to MSDN (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
' 4: Do not display a progress dialog box.
' 256: Display a progress dialog box but do not show the file names.
' Extract the files
oTarget.CopyHere oSource, 256
' Release the objects
Set oSource = Nothing
Set oTarget = Nothing
Set oShell = Nothing
ExtractCompressedFiles = TRUE
Else
LogFail "ExtractCompressedFiles", "Compressed file " & sSourceFile & " was not found."
End If
Set oFS = Nothing
End Function