I am performing the following which works perfectly if there is not an empty
subdirectory within the folder I am trying to zip.
src = "c:\temp\"
dest = "c:\test\test1.zip"
'write zip file header
set fso = createobject("Scripting.FileSystemObject")
set file = fso.opentextfile(dest,forwriting,true)
file.write "PK" & chr(5) & chr(6) & string(18,chr(0))
file.close
set shl = createobject("Shell.Applicatioin")
shl.namespace(dest).copyhere shl.namespace(src).items
do until shl.namespace(dest).items.count = shl.namespace(src).items.count
wscript.sleep 100
loop
However, if there is an empty subdirectory I receive the following error
"The specified directory c:\temp\vbe is empty, so compressed (zipped) folders
cannot add it to the archive.
How do I prevent this from happening. If I do the same thing manually by
right clicking on temp and choosing send to\compressed folder I do not
receive the error.
thanks.
I understood your issue is that VBScript throw an error when tring to
insert an empty subdirectory into compress(zip) folder. If I misunderstood
anything here, please feel free to correct me.
If this is the case, I have reproduced it on my side.
We need to perform more research on this issue . We will reply here as soon
as possible. If you have any more concerns on it, please feel free to post
here.
Thanks for your understanding!
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
This error will be thrown when we drop an Empty Directory into Compress
(zipped) folders. You can try it in Windows Explorer.
"Send to compressed folder" does not copy items into Target Compress folder
directly. It warps them in a folder. Thereby, we didn't received error when
compress a folder with an empty subdirectory.
Try the following method can resolve this issue.
set shl = CreateObject("Shell.Application")
shl.namespace(dest).copyhere shl.namespace(src).self
do until shl.namespace(dest).items.count = 1
wscript.sleep 100
loop
Hope this helps, please feel free to update here again, if there is
anything unclear. We are glad to assist you.
Have a great day,
have read lots about shell not being so dependable.
Also, I have tried using the options specified in the copyhere docs on MSDN
and have had no success. I don't want progress windows or windows to be
displayed if there is an issue. I want to trap them. :)
thanks again.
I consulted shell team. Windows XP or above handles Zip files by
zipfldr.dll (which is located in %windir%\system32\zipfldr.dll). It's a
thrid party product. I'm sorry to say Microsoft doesn't provide any API to
compress Zip via zipfldr.dll.
The MSDN documentation you referenced about CopyHere method only applies to
normal file system path.It doesn't work for a zip file folder. That's why
you find the option 4 to disable the progress dialog doesn't help.It's by
desgin.
By the way, currently the zip file functionality is only meant to be used
with User Interaction. In other words, programmatically access to the zip
file NSE is not officially supported.
Hope this helps.