Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NewFolder on a ZIP file crashes VBScript - What should I do instead ?

180 views
Skip to first unread message

R.Wieser

unread,
Nov 14, 2012, 2:20:50 PM11/14/12
to
Hello All

I'm trying to create a folder in a ZIP-file by using 'NewFolder' on a
NameSpace object representing the ZIP file. Alas, the end result is a
crash:

oZip = objShell.NameSpace("drive:\path\MyFile.zip")
oZip.NewFolder("Test")

Am I doing something wrong here ? If so, what should I do instead ?

Regards.
Rudy Wieser

P.s.
oZip.CopyHere does work.



Ruediger Roesler

unread,
Nov 16, 2012, 7:00:20 AM11/16/12
to
R.Wieser <add...@not.available> typed:

> I'm trying to create a folder in a ZIP-file by using 'NewFolder' on a
> NameSpace object representing the ZIP file. Alas, the end result is a
> crash:
>
> oZip = objShell.NameSpace("drive:\path\MyFile.zip")
> oZip.NewFolder("Test")
>
> Am I doing something wrong here ? If so, what should I do instead ?

If you access an Explorer Folder Object, you have to use the
SET-Statement:
Set oZip = objShell.NameSpace("d:\path\MyFile.zip")

After you have given the command for creating the new folder, you have
to wait until it was created, that can take a few millisecs:

Set fso = CreateObject("Scripting.FileSystemObject")
Do Until fso.FolderExists(fso.BuildPath(oZip.Self.Path, "Test"))
WScript.Sleep 50
Loop

Then you can work with the new folder.

--
ЯR

Dave "Crash" Dummy

unread,
Nov 16, 2012, 10:33:20 AM11/16/12
to
Have you tested this? I get an error with oZip.NewFolder("Test")
--
Crash

Committed to the search for intraterrestrial intelligence.

Ruediger Roesler

unread,
Nov 16, 2012, 11:02:47 AM11/16/12
to
Dave "Crash" Dummy <inv...@invalid.invalid> typed:
No, not tested. oZip.NewFolder was not my code, sorry. I guess, You must
remove the parentheses around the "Test". Or you have to *CALL* the
method:

Call oZip.NewFolder("Test")
oZip.NewFolder "Test"

Some time ago I wrote this function for private need, this was tested:

Private Function Unzip(strZipFldr, strDestFldr, strFile)
Const ZIP = 0, DST = 1: Dim xpFolder(1)

Set xpFolder(ZIP) = xpShell.NameSpace(strZipFldr)
Set xpFolder(DST) = xpShell.NameSpace(strDestFldr)
xpFolder(DST).CopyHere xpFolder(ZIP).ParseName(strFile)
Do Until fso.FileExists(fso.BuildPath(strDestFldr, strFile))
WScript.Sleep 50
Loop

Unzip = xpFolder(DST).ParseName(strFile).Path
End Function

It is important not to quit the function before the copy progress has
finished, because the explorer instance (xpShell) will be destroyed in
that case.

--
ЯR


R.Wieser

unread,
Nov 16, 2012, 11:48:31 AM11/16/12
to
Hello Ruediger,

> If you access an Explorer Folder Object, you have to use the
> SET-Statement:
> Set oZip = objShell.NameSpace("d:\path\MyFile.zip")

My apologies, but I did use that ("set" I mean. I just forgot to type it
into the message).

And when I say "crash" I really do mean that: I get a message stating that
"Microsoft (R) Console Based Scripting Host has encountered a problem and
needs to close. We are sorry for the inconvenience". Thats not the script
throwing an error, that is the OS (in my case XP) barfing. :-\

I just tried to wait for a bit (half a second), but alas, that did not
change the outcome.

Regards,
Rudy Wieser


-- Origional message:
Ruediger Roesler <worm.co...@nospam.arcornews.de> schreef in
berichtnieuws 50a62ad8$0$6563$9b4e...@newsspool4.arcor-online.net...
> ?R
>


Ruediger Roesler

unread,
Nov 16, 2012, 2:39:52 PM11/16/12
to
R.Wieser <add...@not.available> typed:

> My apologies, but I did use that ("set" I mean. I just forgot to type
> it into the message).

Ok

> And when I say "crash" I really do mean that: I get a message stating
> that "Microsoft (R) Console Based Scripting Host has encountered a
> problem and needs to close. We are sorry for the inconvenience".
> Thats not the script throwing an error, that is the OS (in my case
> XP) barfing. :-\
>
> I just tried to wait for a bit (half a second), but alas, that did not
> change the outcome.

I c, it is not supported to create an empty folder in a zip folder with
the explorer shell. This is a work around:

Const ssfPERSONAL = 5 ' Folder that contains user's documents.

Set fso = CreateObject("Scripting.FileSystemObject")
Set xpShell = CreateObject("Shell.Application")

Set xpZipFolder = xpShell.NameSpace("d:\path\MyFile.zip")
Set xpPersonal = xpShell.NameSpace(ssfPERSONAL)

xpPersonal.NewFolder "Test"
With fso.GetFolder(fso.BuildPath(xpPersonal.Self.Path, "Test"))
.CreateTextFile("Dummy").Close
End With
i = xpZipFolder.Items.Count
xpZipFolder.CopyHere xpPersonal.ParseName("Test")

Do Until xpZipFolder.Items.Count = i + 1
WScript.Sleep 16
Loop

Call fso.DeleteFolder(fso.BuildPath(xpPersonal.Self.Path, "Test"))

--
ЯR

R.Wieser

unread,
Nov 17, 2012, 10:30:01 AM11/17/12
to
My apologies for having send the below to your personal email instead of
posting it here. Must have pushed the wrong button :-\


Hello Ruediger,

> I c, it is not supported to create an empty folder in a zip
> folder with the explorer shell.

Well, after I tried to 'CopyHere' an empty folder to the ZIP file and
failing I created a dummy (zero byte) file into the empty folder and
suceeded to copy that one -- very much the same as in your script. Alas,
there is no way to remove the dummy file, and if done thru windows own
filebrowser the (resulting) empty folder disappears. :-\

Funny, I seem to remember that the old DOS/console-based -based variant of
ZIP was able to store empty folders too.

Ggrr... Not funny. yet another "only works of you use it *our* way"
MicroSoft (actually yet another third-party) product

Regards,
Rudy Wieser

----- Original Message -----
Ruediger Roesler <worm.co...@nospam.arcornews.de> schreef in
berichtnieuws 50a696ac$0$6566$9b4e...@newsspool4.arcor-online.net...
> ?R
>


Dave "Crash" Dummy

unread,
Nov 17, 2012, 10:47:02 AM11/17/12
to
R.Wieser wrote:
> My apologies for having send the below to your personal email instead
> of posting it here. Must have pushed the wrong button :-\
>
>
> Hello Ruediger,
>
>> I c, it is not supported to create an empty folder in a zip folder
>> with the explorer shell.
>
> Well, after I tried to 'CopyHere' an empty folder to the ZIP file and
> failing I created a dummy (zero byte) file into the empty folder and
> suceeded to copy that one -- very much the same as in your script.
> Alas, there is no way to remove the dummy file, and if done thru
> windows own filebrowser the (resulting) empty folder disappears. :-\
>
> Funny, I seem to remember that the old DOS/console-based -based
> variant of ZIP was able to store empty folders too.
>
> Ggrr... Not funny. yet another "only works of you use it *our* way"
> MicroSoft (actually yet another third-party) product

Bear in mind that the zip file is not really a folder. Explorer handles
it to make it look like a folder, but it is in fact adding and removing
files from the archive file, not managing the drive tree. You will find
that you cannot create new folders in the zip file with Explorer,
either. You can only copy existing folders.
--
Crash

"When you want to fool the world, tell the truth."
~ Otto von Bismarck ~

R.Wieser

unread,
Nov 17, 2012, 2:56:25 PM11/17/12
to
Hello Dave,

> Bear in mind that the zip file is not really a folder. Explorer
> handles it to make it look like a folder

I know. It only looks like a folder because of its icon. For the rest it
has itself set up as a drop-target and accepts a few DDE commands. Any old
program can do that. :-)

But by making itself look like a folder it generated some expectations. And
those expectations are not met in the slightest. :-\

> You will find that you cannot create new folders in the zip
> file with Explorer, either.

True. The (right-click) context-menu is nothing like for a normal folder,
and does not have a "new -> folder" option. I think I have to conceede that
(this implementation of) ZIP just does not allow the existance of empty
folders. Too bad.

> You can only copy existing folders.

Not quite, just try copying an empty folder into it. You will get a message
it cannot do that. There *must* be a file it it.

Having said that, it should not have been too hard to allow the user to name
an empty folder, as long as he puts files into it before navigating away
from it.

Regards,
Rudy Wieser

Dave "Crash" Dummy <inv...@invalid.invalid> schreef in berichtnieuws
k88bhm$ce1$1...@dont-email.me...
0 new messages