Quantcast
Channel: Can you zip a file from the command prompt using ONLY Windows' built-in capability to zip files? - Super User
Viewing all articles
Browse latest Browse all 14

Answer by kayleeFrye_onDeck for Can you zip a file from the command prompt using ONLY Windows' built-in capability to zip files?

$
0
0

This is a mutation of the accepted answer. I do a ton of automation tasks on up to thousands of files at a time, so I can't just sleep for 2 seconds and not care about it. I gleaned the workaround here, which is also similar to Jiří Kočara's answer here.

This will cause the destination folder to be pinged every 200 ms, which is approximately as fast as Microsoft says to check for file system updates.

Set parameters = WScript.ArgumentsSet FS = CreateObject("Scripting.FileSystemObject")SourceDir = FS.GetAbsolutePathName(parameters(0))ZipFile = FS.GetAbsolutePathName(parameters(1))CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK"& Chr(5) & Chr(6) & String(18, vbNullChar)Set shell = CreateObject("Shell.Application")Set source_objects = shell.NameSpace(SourceDir).ItemsSet ZipDest = shell.NameSpace(ZipFile)Count=ZipDest.Items().Countshell.NameSpace(ZipFile).CopyHere(source_objects)Do While Count = ZipDest.Items().Count    wScript.Sleep 200Loop

Viewing all articles
Browse latest Browse all 14

Trending Articles