NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
Radek_Codr
Posts: 16
0 Kudos
Accepted Solution

How to create a zip file

Hello,

 

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

 

Thank you for advance.

 

Radek

Active Participant
AndreasK
Posts: 200

Re: How to create a zip file

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

Active Participant
AndreasK
Posts: 200

Re: How to create a zip file

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.

Member
Radek_Codr
Posts: 16
0 Kudos

Re: How to create a zip file

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

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page