File Unzip in DIAdem VBScript

Updated May 3, 2018

Reported In

Software

  • DIAdem

Issue Details

I am creating a VBS script in DIAdem. I would like the script to automatically unzip a .zip file, containing any file format.
In DIAdem help, I found Unzip for DataPlugin method but when I try to call it in my DIAdem script I get the following error:

Variable is undefined: 'Unzip'

How can I implement this functionality in a DIAdem script?
 

Solution

Unzip for DataPlugin method is specific for DataPlugin object interface, which can be called in a DataPlugin script and not in a .vbs DIAdem script.
To be able to programmatically unzip a .zip file, you could use standard VBScript functionality (not DIAdem-specific commands). One possible example implementation is as follows:

Dim ZipFile, ExtractTo, fso, objShell, FilesInZip
'Set ZipFile variable to the location of the zip file.
ZipFile="C:\Test.Zip"
'Set ExtractTo variable to the folder the contents should be extracted to.
ExtractTo="C:\Test\"

'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
   fso.CreateFolder(ExtractTo)
End If

'Extract the contents of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip = objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing


This example uses:
  1. FileSystemObject methods to check if the destination directory exists and, if not, programmatically create it
  2. Shell object methods to execute commands within the Shell, in particular to get the Items in the .zip file and copy them in the destination folder

Additional Information

The .vbs script for a DataPlugin does not use DIAdem's VBScript host, but instead uses the more standard Universal Storage Interface (USI) VBScript Host.  Therefore, any DIAdem specific commands, namely any commands that are displayed red or variables that appear green in the DIAdem script editor, will not work with DataPlugins. Also, some specific DataPlugins functions may not work in a DIAdem script.
 

WAS THIS ARTICLE HELPFUL?

Not Helpful