DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a zip file

Solved!
Go to solution

Hello,

 

I would like to ask how to pack exported data from DIAdem to zip?

 

Thank you for advance.

 

Radek

0 Kudos
Message 1 of 4
(5,048 Views)
Solution
Accepted by topic author Radek_Codr

Hello Radek,

 

you can use the gnu tools for win32.

They contain two executables zip.exe and unzip.exe that you can ship for free and use a script like the following.

Takse some time to check the parameters of the two little tools.

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.

dim zipFile : zipFile = CurrentScriptPath & "example.zip"
if FileExist(zipFile) then
  FileDelete zipFile
end if

call AddToZip(zipFile, CurrentScriptPath & CurrentScriptName)

dim outPath : outPath = Unzip(zipFile) 
MsgBox "Extracted to: " & outPath

Sub AddToZip(filePath, fileToAdd)

  dim shell : Set shell = CreateObject("WScript.Shell")
  dim zipCmd : zipCmd = CurrentScriptPath & "\zip.exe"
  dim command : command = """" & zipCmd & """ -D -j """ & filePath & """ """ & fileToAdd & """"
  dim status : status = shell.Run(command, 0, true)
  if(0 <> status) then
    err.Raise 100, "", "zip.exe failed with status " & status & "."
  end if
End Sub

Function Unzip(filePath)
  dim shell : Set shell = CreateObject("WScript.Shell")
  dim tempDir : tempDir = shell.Environment("Process")("Temp") & "\myoutput"

  dim unZipCmd : unZipCmd = CurrentScriptPath & "\unzip.exe"
  dim command : command = """" & unZipCmd & """ -o """ & filePath & """ -d """ & tempDir & """"

  dim status : status = shell.Run(command, 0, true)
  if(0 <> status) then
    err.Raise 100, "", "unzip.exe failed with status " & status & "."
  end if
  Unzip = tempDir
End Function

 

Greetings

Andreas

Message 2 of 4
(5,041 Views)

Since win XP

 

Sub AddToZip(zipFile, folderToZip)

  dim sa : set sa = CreateObject("Shell.Application")
  dim zipFileObj : Set zipFileObj = sa.NameSpace(zipFile)
  dim fol : Set Fol = sa.NameSpace(folderToZip)
  zipFileObj.CopyHere(Fol.Items) 
  
End Sub

Sub Unzip(zipFile, unzipToFolder)

  dim sa : set sa = CreateObject("Shell.Application")
  dim filesInzip : set filesInzip = sa.NameSpace(zipFile).items
  sa.NameSpace(unzipToFolder).CopyHere(filesInzip) 

End Sub

 seems to work too.

Message 3 of 4
(5,032 Views)

Thanks for the advice, but packing using second method does not work. I think you need to first create a Zip file, including the appropriate header, and then you can write to him.

 

Sub Zip(sFile, sZipFile)
	Set oZipFSO = CreateObject("Scripting.FileSystemObject")
	Set oZipFile = oZipFSO.CreateTextFile(sZipFile)
	oZipFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
	
	Set oZipApp = CreateObject("Shell.Application")
	oZipApp.NameSpace(sZipFile).Copyhere sFile
End Sub

 

Some example can be seen on: http://www.naterice.com/articles/64

 

Radek

0 Kudos
Message 4 of 4
(4,964 Views)