Zip a folder, files and Subfolder

cutecupid
cutecupid used Ask the Experts™
on
uSING vbscript, i need to zip files and sub folder of a folder.
Note: I am having Winzip in my local desktop
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi, I think this VBS code should work with Winzip.

Regards,

Rob.

strDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

strFolderToZip = "C:\Temp\Scripts"
strZipFileToCreate = "C:\Temp\Scripts_" & strDate & ".zip"
strWinzip = "C:\Program Files\WinZip\Winzip32.exe"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strWinZip = objFSO.GetFile(strWinZip).ShortPath
strCommand = strWinzip & " -min -a -r """ & strZipFileToCreate & """ """ & strFolderToZip & """"
objShell.Run strCommand, 1, True

MsgBox "Done"

Open in new window

Commented:
There are a number of examples on this page for zipping folders using VBScript.

The second script looks the most comprehensive as it handles empty sub folders

http://www.robvanderwoude.com/vbstech_files_zip.php

Author

Commented:
---------------------------
Windows Script Host
---------------------------
Script:      D:\New_project\zippingafolder.vbs
Line:      9
Char:      1
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Commented:
?

We will need a sample of the code you ran in order to work out what is wrong.

Quite simply from that error it is suggesting that it could not find the file, besides that there is not much more we can tell.  I would presume the path to the file is incorrect in the code you ran.

Author

Commented:
strDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

strFolderToZip = "D:\New_project\test"
strZipFileToCreate = "D:\New_project\test\Scripts_" & strDate & ".zip"
strWinzip = "C:\Program Files\WinZip\Winzip32.exe"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strWinZip = objFSO.GetFile(strWinZip).ShortPath
strCommand = strWinzip & " -min -a -r """ & strZipFileToCreate & """ """ & strFolderToZip & """"
objShell.Run strCommand, 1, True

MsgBox "Done"
Commented:
Line 9 refers back to line 5:  where it sets the string strWinzip to  C:\Program Files\WinZip\Winzip32.exe

What happens if you go to Start - Run and paste the line:
C:\Program Files\WinZip\Winzip32.exe
and hit Enter

if you have winzip installed on your PC and it is in that location then it should open the winzip program - if not you will get a fail

Author

Commented:
[Window Title]
C:\Program

[Content]
Windows cannot find 'C:\Program'. Make sure you typed the name correctly, and then try again.

[OK]

Commented:
Unsual if you can not see the C: Program folder, but that could be down to a different language installation e.g. the word program is sometimes written in the local insallation language.   I presume that you are also using windows.

To get round all of this and as long as you you have Winzip installed on your PC, browse to the location of the Winzip32.exe file where ever it is installed on the PC (do a search if you can't find it) and copy the path of it into the script.

Author

Commented:
thanks your effort, it worked well for me..

thanks a lot ...

Author

Commented:
Really good guidance

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial