File Compression: Automation
My goal is to automate the functionality of WinZip from within a Visual Basic 6.0 application.
In my efforts I have created a dll as a wrapper to the WinZip utility. The initial results
appeared to work well. The program uses the WinZip Command Line Add-On, a beta release, and WinZip 9.0 a beta release also. Initially I had used the Windows Scripting Host Object (WSHom) to make the calls to the command line. But, we experienced problems when the file name exceeded 15 characters. Not a problem for new releases but this application has to work with legacy files as well. When investigating a resolution I now understand the Windows Scripting Host cannot handle long file name. Also, the API ShortPathName( ) only returns a value if a file already exist. I read that if you enclose the command in double quotation marks the WSHom will accept it. But I was unable to get that to execute anything?
Since then I have changed the application to use the Shell( ) function. It appears to be working only about half of the time with various errors. WinZip itself never returns any errors? These are the two problems I have been encountering.
1. WinZip will execute but no file will be made. I have noticed this when executed within a For loop. To try and resolve this issue I have added a function to check for the existence of the file prior to executing the next loop. This has added considerable time to our application but seemed to resolve the situation minus the following problem.
2. WinZip will create the zipped file however the original file is not in the zipped file and
the file size is 0 kb.
Perhaps I have misunderstood the purpose of the utility.
Here are some samples of the command line arguments being executed:
' The following code is only for reference purposes
' The actual code is dynamic but this should enable you
' to better understand what is happening in the program
Dim lError as Long
Dim dX as Double
Dim strArg as String
Dim ws As WshShell ' Reference wshom.ocz
' Successful command using WSHom.ocx
strARG = "COMMAND.COM /C C:\PROGRA~1\WinZip\wzzip.exe -ee -o -jhrs" & Chr(34) & "C:\Temp\Vault\5108889510889.dwg.zip" & Chr(34) & "C:\Larry\COPYOF~1\5108889510889.dwg"
lError = ws.Run(strArg, vbMinimizedNoFocus, True)
' Failed command using WSHom.ocx
strARG = "COMMAND.COM /C C:\PROGRA~1\WinZip\wzzip.exe -ee -o -jhrs" & Chr(34) & "C:\Temp\Vault\51088895108890.dwg.zip" & Chr(34) & "C:\Larry\COPYOF~1\51088895108890.dwg"
lError = ws.Run(strArg, vbMinimizedNoFocus, True)
' Command executed using the shell function
strArg = "C:\PROGRA~1\WinZip\wzzip.exe -ee -o -jhrs" & Chr(34) &
"C:\Temp\Vault\51088895108890.dwg.zip" & Chr(34) & C:\Larry\COPYOF~1\51088895108890.dwg"
dx = Shell(strArg, vbMinimizedNoFocus)
Please offer your advise. At this point I am looking to either resolve the issue with
the Windows Scripting Host Object. But I am more inclined to look at an alternative to
WinZip.
Thanks in advance for your help,
Larry Asher
__________________
Larry Asher
|