1

I want to add all files of a directory into a ZIP file. I use the code below from Can you zip a file from the command prompt using ONLY Windows' built-in capability to zip files? But this VB script is very slow.

How can I make this action faster?

'Get command-line arguments.
Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
ZipFile = objArgs(1)

'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

Set objShell = CreateObject("Shell.Application")

Set source = objShell.NameSpace(InputFolder).Items

objShell.NameSpace(ZipFile).CopyHere(source)

'Required!
wScript.Sleep 2000
Community
  • 1
  • 1
dev_user
  • 11
  • 2
  • You can't. You are using shell objects which are slow. Use a program like winzip http://www.winzip.com/prodpagecl.html –  Jun 11 '16 at 20:59
  • There's a free component I learned about from Rob Vander Woud - X-Zip.. he has some code samples here. I don't think you could do this natively but that X-zip seems to be useful for your use-case. Using a language like C++/C# might be optimial to achieve what you're looking for though. http://www.robvanderwoude.com/vbstech_files_zip.php – Steve Kline Jun 12 '16 at 02:53
  • 1
    There are lots of freeware and shareware archivers supporting ZIP like 7-Zip, Info-ZIP, WinRAR, WinZip, etc. written for adding files and directories into a file using ZIP compression. They are all much faster than what Windows offers by default. See also [How can I compress (zip) and uncompress (unzip) files and folders with batch file without using any external tools?](http://stackoverflow.com/questions/28043589/) – Mofi Jun 12 '16 at 09:24
  • If you use WinZip, there is a command line utility kit to be installed. 7-zip is good. – lit Jun 14 '16 at 20:04

1 Answers1

-1

I prefer using Batch files this is the code:

@echo off

echo Iam.zip

Move test.txt Iam.zip
HebeleHododo
  • 3,620
  • 1
  • 29
  • 38