Link to home
Start Free TrialLog in
Avatar of Midhun 123
Midhun 123

asked on

To zip pdf files using batch script

Hi All,

Greetings...

According to my work, I need to zip files present in a folder using batch script without using any 3rd party software.

I tried with below code ,but getting the error.error also attached below.

Any help regarding this would be highly appreciated.
'Get command-line arguments.
Set objArgs = WScript.Arguments
Set FS = CreateObject("Scripting.FileSystemObject")
InputFolder = FS.GetAbsolutePathName(objArgs(0))
ZipFile = FS.GetAbsolutePathName(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

Open in new window


This code is present in zip.vbs file. We have to zip the files into Outputfile.zip file.
in command prompt  , I have entered below command

C:\Users\abc>Cscript zip.vbs input path  output path\OutputFile.zip

While executing this ,I got below error. " Path not found error" for both the input and output file path.

It will be helpful if anyone corrects me the mistake which I made in this script.
Avatar of HainKurt
HainKurt
Flag of Canada image

try

Cscript zip.vbs "input path"  "output path\OutputFile.zip"

Open in new window

or use wscript instead of Cscript
Avatar of Shaun Vermaak
I would honestly just use the 7z command line version, 7za.exe
http://www.7-zip.org/download.html

7za a -zip files.zip *.pdf

Open in new window

Shaun, "without using any 3rd party software".
Hain, how should WScript help with that?
Hain, how should WScript help with that?

maybe you are running with wrong engine... so use WScript in command line + wrap path with quotes

Cscript zip.vbs "input path"  "output path\OutputFile.zip"

Open in new window


>>>

WScript zip.vbs "input path"  "output path\OutputFile.zip"

Open in new window

Avatar of Midhun 123
Midhun 123

ASKER

Thank You all for your response.

We have winzip installed in our machine and can use this for zipping .

Is there any other way to zip files using batch script and winzip ??

I tried with below code ..But unfortunately It didn't work as expected.
@echo off
wzzip "OutPutFile Path\Filename""Input folder path"

Open in new window


But I am not sure should we point it first into WinZip installation path.

Thanks in Advance..
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the path of wzzip isn't in the PATH environment variable, it cannot be found. Do you get an error that it is not found?

The correct command would be wzzip -a -P -r "OutPutFile Path\Filename" "Input folder path\*" with -a being optional, but you need to run that in the folder those folder and file references start in, unless you use absolute paths. And you might have to put the path of [b}wzzip[/b] in front of it if it isn't found otherwise.
Note: -P stores the complete path, -p the relative path based on "Input folder path" (that is, this folder is not included in the zip file).
It worked perfectly
Shaun, "without using any 3rd party software".
WinZip is 3rd party and not free. 7za is a free command line version of 7z
I agree using WinZip looks to be out of the scope of this question; it should have been something along "we cannot install additional software, but we've WinZip if that helps".