0

I am trying to use a batch file to zip all the files and folders in a particular directory into one zipped folder without using WinRAR, WinZip or 7Zip.

More specifically: Let's say I have a folder called Files\ I would like to create a batch file that zips everything in Files\ to a new .zip file inside the Files\ folder called something like "MyZippedFile.zip".

Any help would be greatly appreciated!

user2972067
  • 11
  • 1
  • 3

2 Answers2

0

Zips are folders. This copies from one fodler to another.

'Zip.vbs - needs an existing zip file
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"

'Unzip.vbs - needs existing unzip directory
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set DestFldr=objShell.NameSpace(Ag(1))
Set SrcFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"

'CreateBlankZip.vbs
Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
    BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip
David Candy
  • 735
  • 5
  • 8
  • Hi David - this seems extremely helpful, but I still can't seem to get it working... I apologize for my ignorance. Is this script you wrote suppposed to be in a .vbs or a .bat file? And when you say " 'Zip.vbs - needs an existing zip file" and " 'Unzip.vbs - needs an existing unzip directory ", and 'CreateBlankZip.vbs" - are those separate files that I would need to create or is this one big file? – user2972067 Nov 10 '13 at 13:03
0

I created the VBS script found at zipping files from different folders preserving the directory structure to backup directories and files using only the built in widows compression functionality. It only zips files and folders, no unzipping. Keeps the folders intact.

Put the code in a file (e.g. BackZip.vbs) and execute it with wscript.exe which is included in most computers with .NET. (e.g. wscript.exe BackZip.vbs /X "C:\My Folder\") It only needs .NET revision 2.0 or more, which was released in 2005.

A lot of the code revolves around handling individual files, but if you're only doing folders you could remove a lot of the code.

Community
  • 1
  • 1
HexaGamnon
  • 93
  • 1
  • 6