Discussion:
VB Script for creating zip file and copying files into it.
(too old to reply)
Chitra Balasubramani
2016-11-28 06:57:59 UTC
Permalink
Hello,

I'm trying to create a zip file and copy files into it via VBS code.


Problem is Files are not getting copied, only zip file is getting created.



Here is my code :

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2, True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set ts = nothing

WScript.Sleep 5000


Set objShell = CreateObject("Shell.Application")
Set DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Set SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
DestFldr.CopyHere SrcFldr

Thanks in advance.
R.Wieser
2016-11-28 08:24:40 UTC
Permalink
Chitra,
Post by Chitra Balasubramani
Problem is Files are not getting copied, only zip file is getting created.
Try ading a "sleep" after the CopyHere command, and see what happens.

Explanation: When the CopyHere has been requested, but the actual copying
hasn't started yet (it takes a bit of time to gather all the neccesary file
info) the ending of the script closes the ZIP object, not giving it a chance
to actually start the copying (when the process is started the ZIP object
will not close until it has finished copying)

Regards,
Rudy Wieser
Post by Chitra Balasubramani
Hello,
I'm trying to create a zip file and copy files into it via VBS code.
Problem is Files are not getting copied, only zip file is getting created.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2, True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Post by Chitra Balasubramani
Set
SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
Post by Chitra Balasubramani
DestFldr.CopyHere SrcFldr
Thanks in advance.
Chitra Balasubramani
2016-11-28 10:25:42 UTC
Permalink
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Problem is Files are not getting copied, only zip file is getting created.
Try ading a "sleep" after the CopyHere command, and see what happens.
Explanation: When the CopyHere has been requested, but the actual copying
hasn't started yet (it takes a bit of time to gather all the neccesary file
info) the ending of the script closes the ZIP object, not giving it a chance
to actually start the copying (when the process is started the ZIP object
will not close until it has finished copying)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Hello,
I'm trying to create a zip file and copy files into it via VBS code.
Problem is Files are not getting copied, only zip file is getting created.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2,
True)
Post by Chitra Balasubramani
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Post by Chitra Balasubramani
Set
SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
Post by Chitra Balasubramani
DestFldr.CopyHere SrcFldr
Thanks in advance.
Wieser,

Thanks for the response.

Tried adding sleep. Now getting "Access Denied Error"


ZipFile = "C:\apace-jmeter-3\bin\Results\outcome.zip"
SourceFolder ="C:\Users\chitra.balasubramani\Desktop\Mail"

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(ZipFile, True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
ts.Close
Set ts = Nothing
Set fso = Nothing

Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

' Get items in source folder
Set sourceItems = CreateObject("Shell.Application").NameSpace(SourceFolder).Items

' Add all files/directories to the .zip file
zip.CopyHere(sourceItems)
WScript.Sleep 5000 'Wait for items to be copied

Thanks,
Chitra
R.Wieser
2016-11-28 10:48:07 UTC
Permalink
Chitra,
Post by Chitra Balasubramani
Tried adding sleep. Now getting "Access Denied Error"
That seems to mean that the CopyHere is actually trying to copy some
file(s). :-)

I get the feeling that you get that error because one of the files in
"C:\Users\chitra.balasubramani\Desktop\Mail" is still in use (is your mail
program still running ? If so, close it before running the script).

Have you tried to just copy those files to a temporary normal folder and see
if you get the same error (using VBScript but also try drag-and-dropping
them using the file/windows explorer) ?

Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Problem is Files are not getting copied, only zip file is getting created.
Try ading a "sleep" after the CopyHere command, and see what happens.
Explanation: When the CopyHere has been requested, but the actual copying
hasn't started yet (it takes a bit of time to gather all the neccesary file
info) the ending of the script closes the ZIP object, not giving it a chance
to actually start the copying (when the process is started the ZIP object
will not close until it has finished copying)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Hello,
I'm trying to create a zip file and copy files into it via VBS code.
Problem is Files are not getting copied, only zip file is getting created.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2,
True)
Post by Chitra Balasubramani
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Post by Chitra Balasubramani
Set
SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
Post by Chitra Balasubramani
DestFldr.CopyHere SrcFldr
Thanks in advance.
Wieser,
Thanks for the response.
Tried adding sleep. Now getting "Access Denied Error"
ZipFile = "C:\apace-jmeter-3\bin\Results\outcome.zip"
SourceFolder ="C:\Users\chitra.balasubramani\Desktop\Mail"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(ZipFile, True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
ts.Close
Set ts = Nothing
Set fso = Nothing
Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)
' Get items in source folder
Set sourceItems =
CreateObject("Shell.Application").NameSpace(SourceFolder).Items
Post by Chitra Balasubramani
' Add all files/directories to the .zip file
zip.CopyHere(sourceItems)
WScript.Sleep 5000 'Wait for items to be copied
Thanks,
Chitra
Chitra Balasubramani
2016-11-28 10:47:48 UTC
Permalink
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Tried adding sleep. Now getting "Access Denied Error"
That seems to mean that the CopyHere is actually trying to copy some
file(s). :-)
I get the feeling that you get that error because one of the files in
"C:\Users\chitra.balasubramani\Desktop\Mail" is still in use (is your mail
program still running ? If so, close it before running the script).
Have you tried to just copy those files to a temporary normal folder and see
if you get the same error (using VBScript but also try drag-and-dropping
them using the file/windows explorer) ?
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Problem is Files are not getting copied, only zip file is getting
created.
Post by Chitra Balasubramani
Post by R.Wieser
Try ading a "sleep" after the CopyHere command, and see what happens.
Explanation: When the CopyHere has been requested, but the actual
copying
Post by Chitra Balasubramani
Post by R.Wieser
hasn't started yet (it takes a bit of time to gather all the neccesary
file
Post by Chitra Balasubramani
Post by R.Wieser
info) the ending of the script closes the ZIP object, not giving it a
chance
Post by Chitra Balasubramani
Post by R.Wieser
to actually start the copying (when the process is started the ZIP
object
Post by Chitra Balasubramani
Post by R.Wieser
will not close until it has finished copying)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Hello,
I'm trying to create a zip file and copy files into it via VBS code.
Problem is Files are not getting copied, only zip file is getting
created.
Post by Chitra Balasubramani
Post by R.Wieser
Post by Chitra Balasubramani
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip",
2,
Post by Chitra Balasubramani
Post by R.Wieser
True)
Post by Chitra Balasubramani
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Post by Chitra Balasubramani
Set
SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
Post by Chitra Balasubramani
DestFldr.CopyHere SrcFldr
Thanks in advance.
Wieser,
Thanks for the response.
Tried adding sleep. Now getting "Access Denied Error"
ZipFile = "C:\apace-jmeter-3\bin\Results\outcome.zip"
SourceFolder ="C:\Users\chitra.balasubramani\Desktop\Mail"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(ZipFile, True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
ts.Close
Set ts = Nothing
Set fso = Nothing
Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)
' Get items in source folder
Set sourceItems =
CreateObject("Shell.Application").NameSpace(SourceFolder).Items
Post by Chitra Balasubramani
' Add all files/directories to the .zip file
zip.CopyHere(sourceItems)
WScript.Sleep 5000 'Wait for items to be copied
Thanks,
Chitra
I tired copying to normal folder, instead of zip. That worked fine.
R.Wieser
2016-11-28 11:21:12 UTC
Permalink
Chitra,
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Hmmm ...

There is one more thing you can try: Try changing

zip.CopyHere(sourceItems)

to

zip.CopyHere(sourceItems.items)

(the former will copy the foldername too, the latter only the files in that
folder)

If that does not work you could choose to first copy the needed files to a
temporay folder (which you could create and remove in the script itself),
and from there copy them into the ZIP file. Yes, I know that that is a
work-around, but if the direct way fails you need to come up with a fix. :-)

Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Tried adding sleep. Now getting "Access Denied Error"
That seems to mean that the CopyHere is actually trying to copy some
file(s). :-)
I get the feeling that you get that error because one of the files in
"C:\Users\chitra.balasubramani\Desktop\Mail" is still in use (is your mail
program still running ? If so, close it before running the script).
Have you tried to just copy those files to a temporary normal folder and see
if you get the same error (using VBScript but also try drag-and-dropping
them using the file/windows explorer) ?
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Chitra Balasubramani
2016-11-28 12:07:06 UTC
Permalink
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Hmmm ...
There is one more thing you can try: Try changing
zip.CopyHere(sourceItems)
to
zip.CopyHere(sourceItems.items)
(the former will copy the foldername too, the latter only the files in that
folder)
If that does not work you could choose to first copy the needed files to a
temporay folder (which you could create and remove in the script itself),
and from there copy them into the ZIP file. Yes, I know that that is a
work-around, but if the direct way fails you need to come up with a fix. :-)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Tried adding sleep. Now getting "Access Denied Error"
That seems to mean that the CopyHere is actually trying to copy some
file(s). :-)
I get the feeling that you get that error because one of the files in
"C:\Users\chitra.balasubramani\Desktop\Mail" is still in use (is your
mail
Post by Chitra Balasubramani
Post by R.Wieser
program still running ? If so, close it before running the script).
Have you tried to just copy those files to a temporary normal folder and
see
Post by Chitra Balasubramani
Post by R.Wieser
if you get the same error (using VBScript but also try drag-and-dropping
them using the file/windows explorer) ?
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Wieser,

If the dest folder is "Set DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\Temp")", Copy is working.

If the dest is Set DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")", getting access denied error.

Changed copyHere as "DestFldr.CopyHere (SrcFldr.Items)"

Thanks,
CHitra
R.Wieser
2016-11-28 16:04:30 UTC
Permalink
Chitra (is that your first name ? I'm not sure),
Post by Chitra Balasubramani
If the dest folder is "Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\Temp")", Copy is working.
If the dest is Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\outcome.zip")", getting access
denied error.
Hmmm ... I assumed the sourcefile(s) could be unreadable (because some
other program still has (one of) them open, but its possible that the target
file (the .ZIP) is the actual culprit here.

Have you already tried to open the created (but presumably empty) .ZIP file
? Can you ? If so, whats inside (folders, files)

Your code create the empty ZIP file like this:

ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )

could you try it like this:

ts.Write chr(80) & chr(75) & Chr(5) & Chr(6) & String( 18, 0)

Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Hmmm ...
There is one more thing you can try: Try changing
zip.CopyHere(sourceItems)
to
zip.CopyHere(sourceItems.items)
(the former will copy the foldername too, the latter only the files in that
folder)
If that does not work you could choose to first copy the needed files to a
temporay folder (which you could create and remove in the script itself),
and from there copy them into the ZIP file. Yes, I know that that is a
work-around, but if the direct way fails you need to come up with a fix. :-)
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
Wieser,
If the dest folder is "Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\Temp")", Copy is
working.
Post by Chitra Balasubramani
If the dest is Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")",
getting access denied error.
Post by Chitra Balasubramani
Changed copyHere as "DestFldr.CopyHere (SrcFldr.Items)"
Thanks,
CHitra
Chitra Balasubramani
2016-11-29 04:06:14 UTC
Permalink
Post by R.Wieser
Chitra (is that your first name ? I'm not sure),
Post by Chitra Balasubramani
If the dest folder is "Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\Temp")", Copy is working.
If the dest is Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\outcome.zip")", getting access
denied error.
Hmmm ... I assumed the sourcefile(s) could be unreadable (because some
other program still has (one of) them open, but its possible that the target
file (the .ZIP) is the actual culprit here.
Have you already tried to open the created (but presumably empty) .ZIP file
? Can you ? If so, whats inside (folders, files)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
ts.Write chr(80) & chr(75) & Chr(5) & Chr(6) & String( 18, 0)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Hmmm ...
There is one more thing you can try: Try changing
zip.CopyHere(sourceItems)
to
zip.CopyHere(sourceItems.items)
(the former will copy the foldername too, the latter only the files in
that
Post by Chitra Balasubramani
Post by R.Wieser
folder)
If that does not work you could choose to first copy the needed files to
a
Post by Chitra Balasubramani
Post by R.Wieser
temporay folder (which you could create and remove in the script
itself),
Post by Chitra Balasubramani
Post by R.Wieser
and from there copy them into the ZIP file. Yes, I know that that is a
work-around, but if the direct way fails you need to come up with a fix.
:-)
Post by Chitra Balasubramani
Post by R.Wieser
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
Wieser,
If the dest folder is "Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\Temp")", Copy is
working.
Post by Chitra Balasubramani
If the dest is Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")",
getting access denied error.
Post by Chitra Balasubramani
Changed copyHere as "DestFldr.CopyHere (SrcFldr.Items)"
Thanks,
CHitra
Yes Chitra is my first name :)

Have tried below options :
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access Denied error.

So the problem is VBS is not able to copy files to any of the zip files.

And also if manually copy files to the same empty zip file, it is allowing.

And answer to your question, after running script, Zip is empty.
Evertjan.
2016-11-29 07:16:01 UTC
Permalink
Post by Chitra Balasubramani
So the problem is VBS is not able to copy files to any of the zip files.
And also if manually copy files to the same empty zip file, it is allowing.
And answer to your question, after running script, Zip is empty.
I would think you cannot "copy" a file to a zip-file,
as it involves compression not available to the basic operating system,
and a zip-dile is not [just] a folder/directory.

Is this only a Q of semantics?

Your ordeal suggests otherwise.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Chitra Balasubramani
2016-11-29 10:36:36 UTC
Permalink
Post by Evertjan.
Post by Chitra Balasubramani
So the problem is VBS is not able to copy files to any of the zip files.
And also if manually copy files to the same empty zip file, it is allowing.
And answer to your question, after running script, Zip is empty.
I would think you cannot "copy" a file to a zip-file,
as it involves compression not available to the basic operating system,
and a zip-dile is not [just] a folder/directory.
Yes that's what happening. Able to copy to normal folder not zip files.
Post by Evertjan.
Is this only a Q of semantics?
Your ordeal suggests otherwise.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
R.Wieser
2016-11-29 07:28:02 UTC
Permalink
Chitra,
Post by Chitra Balasubramani
Yes Chitra is my first name :)
:-) I was asking because you adressed me by my sirname, making me wonder if
I was talking to someone in a region where the persons own name is written
last, and the sirname first.
Post by Chitra Balasubramani
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access Denied error.
That seems to indicate that the sourcefiles are not the problem.
Post by Chitra Balasubramani
And also if manually copy files to the same empty zip file, it is allowing.
And answer to your question, after running script, Zip is empty.
That means that the (empty) ZIP file itself is of the right structure.

Could you test what happens when you try to CopyHere to a .ZIP file you
created manually (not by script) ?

If that does *not* work than I am out of ideas I'm afraid.

If it works its possible that the .ZIP file is not actually closed before
you try to CopyHere to it. In that case putting a "sleep" between ... Hold
the presses!

I just took another look at the code you posted, and only now noticed
something I should have much earlier: where do you *close* the .ZIP file
after you've created it ?

Try adding "ts.close" just below the "Set ts = fso.OpenTextFile(...)" line
and see what happens.

Explanation: If the file is still open when the CopyHere command tries to
access it (trying to open it itself) it won't work.

Hope that helps,

Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra (is that your first name ? I'm not sure),
Post by Chitra Balasubramani
If the dest folder is "Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\Temp")", Copy is working.
If the dest is Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\outcome.zip")", getting access
denied error.
Hmmm ... I assumed the sourcefile(s) could be unreadable (because some
other program still has (one of) them open, but its possible that the target
file (the .ZIP) is the actual culprit here.
Have you already tried to open the created (but presumably empty) .ZIP file
? Can you ? If so, whats inside (folders, files)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
ts.Write chr(80) & chr(75) & Chr(5) & Chr(6) & String( 18, 0)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked fine.
Hmmm ...
There is one more thing you can try: Try changing
zip.CopyHere(sourceItems)
to
zip.CopyHere(sourceItems.items)
(the former will copy the foldername too, the latter only the files in
that
Post by Chitra Balasubramani
Post by R.Wieser
folder)
If that does not work you could choose to first copy the needed files to
a
Post by Chitra Balasubramani
Post by R.Wieser
temporay folder (which you could create and remove in the script
itself),
Post by Chitra Balasubramani
Post by R.Wieser
and from there copy them into the ZIP file. Yes, I know that that is a
work-around, but if the direct way fails you need to come up with a fix.
:-)
Post by Chitra Balasubramani
Post by R.Wieser
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
Wieser,
If the dest folder is "Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\Temp")", Copy is
working.
Post by Chitra Balasubramani
If the dest is Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")",
Post by Chitra Balasubramani
Post by R.Wieser
getting access denied error.
Post by Chitra Balasubramani
Changed copyHere as "DestFldr.CopyHere (SrcFldr.Items)"
Thanks,
CHitra
Yes Chitra is my first name :)
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access Denied error.
So the problem is VBS is not able to copy files to any of the zip files.
And also if manually copy files to the same empty zip file, it is allowing.
And answer to your question, after running script, Zip is empty.
Evertjan.
2016-11-29 07:47:11 UTC
Permalink
Post by R.Wieser
:-) I was asking because you adressed me by my sirname, making me wonder if
I was talking to someone in a region where the persons own name is written
last, and the sirname first.
"Sir Rudy"?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
R.Wieser
2016-11-29 07:59:10 UTC
Permalink
Evertjan,
Post by Evertjan.
"Sir Rudy"?
Finally, someone who acknowledges my grandness ! :-D

No, Chitra started his messages by adressing me by just my last name (no
"mr" prefix or alike). Which made me wonder if I was maybe (mistakingly!)
doing the same (adressing him by just his last name) because of a possible
different ordering of (what westerlings call) the first and last/sirname.

Regards,
Rudy Wieser
Post by Evertjan.
Post by R.Wieser
:-) I was asking because you adressed me by my sirname, making me wonder if
I was talking to someone in a region where the persons own name is written
last, and the sirname first.
"Sir Rudy"?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Chitra Balasubramani
2016-11-29 09:37:48 UTC
Permalink
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Yes Chitra is my first name :)
:-) I was asking because you adressed me by my sirname, making me wonder if
I was talking to someone in a region where the persons own name is written
last, and the sirname first.
Post by Chitra Balasubramani
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access Denied
error.
That seems to indicate that the sourcefiles are not the problem.
Post by Chitra Balasubramani
And also if manually copy files to the same empty zip file, it is
allowing.
Post by Chitra Balasubramani
And answer to your question, after running script, Zip is empty.
That means that the (empty) ZIP file itself is of the right structure.
Could you test what happens when you try to CopyHere to a .ZIP file you
created manually (not by script) ?
If that does *not* work than I am out of ideas I'm afraid.
If it works its possible that the .ZIP file is not actually closed before
you try to CopyHere to it. In that case putting a "sleep" between ... Hold
the presses!
I just took another look at the code you posted, and only now noticed
something I should have much earlier: where do you *close* the .ZIP file
after you've created it ?
Try adding "ts.close" just below the "Set ts = fso.OpenTextFile(...)" line
and see what happens.
Explanation: If the file is still open when the CopyHere command tries to
access it (trying to open it itself) it won't work.
Hope that helps,
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra (is that your first name ? I'm not sure),
Post by Chitra Balasubramani
If the dest folder is "Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\Temp")", Copy is working.
If the dest is Set DestFldr=objShell.NameSpace(
"C:\apace-jmeter-3\bin\Results\outcome.zip")", getting access
denied error.
Hmmm ... I assumed the sourcefile(s) could be unreadable (because some
other program still has (one of) them open, but its possible that the
target
Post by Chitra Balasubramani
Post by R.Wieser
file (the .ZIP) is the actual culprit here.
Have you already tried to open the created (but presumably empty) .ZIP
file
Post by Chitra Balasubramani
Post by R.Wieser
? Can you ? If so, whats inside (folders, files)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
ts.Write chr(80) & chr(75) & Chr(5) & Chr(6) & String( 18, 0)
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
I tired copying to normal folder, instead of zip. That worked
fine.
Post by Chitra Balasubramani
Post by R.Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Hmmm ...
There is one more thing you can try: Try changing
zip.CopyHere(sourceItems)
to
zip.CopyHere(sourceItems.items)
(the former will copy the foldername too, the latter only the files
in
Post by Chitra Balasubramani
Post by R.Wieser
that
Post by Chitra Balasubramani
Post by R.Wieser
folder)
If that does not work you could choose to first copy the needed
files to
Post by Chitra Balasubramani
Post by R.Wieser
a
Post by Chitra Balasubramani
Post by R.Wieser
temporay folder (which you could create and remove in the script
itself),
Post by Chitra Balasubramani
Post by R.Wieser
and from there copy them into the ZIP file. Yes, I know that that
is a
Post by Chitra Balasubramani
Post by R.Wieser
Post by Chitra Balasubramani
Post by R.Wieser
work-around, but if the direct way fails you need to come up with a
fix.
Post by Chitra Balasubramani
Post by R.Wieser
:-)
Post by Chitra Balasubramani
Post by R.Wieser
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
Wieser,
If the dest folder is "Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\Temp")", Copy
is
Post by Chitra Balasubramani
Post by R.Wieser
working.
Post by Chitra Balasubramani
If the dest is Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")",
Post by Chitra Balasubramani
Post by R.Wieser
getting access denied error.
Post by Chitra Balasubramani
Changed copyHere as "DestFldr.CopyHere (SrcFldr.Items)"
Thanks,
CHitra
Yes Chitra is my first name :)
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access Denied
error.
Post by Chitra Balasubramani
So the problem is VBS is not able to copy files to any of the zip files.
And also if manually copy files to the same empty zip file, it is
allowing.
Post by Chitra Balasubramani
And answer to your question, after running script, Zip is empty.
Rudy,

Yes the problem is "CopyHere" failing for the empty zip created manually.

Thanks,
Chitra
R.Wieser
2016-11-29 10:58:28 UTC
Permalink
Chitra,
Post by Chitra Balasubramani
Yes the problem is "CopyHere" failing for the empty zip created manually.
I hope you remembered to disable the (re-)creating of the .ZIP file when you
did that (also, add the "close" command. It may not help, but it won't hurt
either) ?

As a (very) last test, what happens when you try to CopyHere a simple
textfile into the (manually) created .ZIP file ?

If that fails I'm really outof ideas I'm afraid.

.. Nope, one more: try changing.

Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2,
True)

to

Set ts = fso.CreateTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip")


I just did something I should have done long before: I ran your script on my
XPsp3 machine. And after adding a "Sleep" at the end it copied a folder to
the created .ZIP file without a problem. And that means I am *really*
outof ideas.

I almost get the feeling as if something else is interfeering with the
copying process. Like an AV product perhaps ...

Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Yes Chitra is my first name :)
:-) I was asking because you adressed me by my sirname, making me wonder if
I was talking to someone in a region where the persons own name is written
last, and the sirname first.
Post by Chitra Balasubramani
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access Denied
error.
That seems to indicate that the sourcefiles are not the problem.
Post by Chitra Balasubramani
And also if manually copy files to the same empty zip file, it is
allowing.
Post by Chitra Balasubramani
And answer to your question, after running script, Zip is empty.
That means that the (empty) ZIP file itself is of the right structure.
Could you test what happens when you try to CopyHere to a .ZIP file you
created manually (not by script) ?
If that does *not* work than I am out of ideas I'm afraid.
If it works its possible that the .ZIP file is not actually closed before
you try to CopyHere to it. In that case putting a "sleep" between ...
Hold
Post by Chitra Balasubramani
Post by R.Wieser
the presses!
I just took another look at the code you posted, and only now noticed
something I should have much earlier: where do you *close* the .ZIP file
after you've created it ?
Try adding "ts.close" just below the "Set ts = fso.OpenTextFile(...)" line
and see what happens.
Explanation: If the file is still open when the CopyHere command tries to
access it (trying to open it itself) it won't work.
Hope that helps,
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
Rudy,
Yes the problem is "CopyHere" failing for the empty zip created manually.
Thanks,
Chitra
Chitra Balasubramani
2016-11-30 03:49:44 UTC
Permalink
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Yes the problem is "CopyHere" failing for the empty zip created manually.
I hope you remembered to disable the (re-)creating of the .ZIP file when you
did that (also, add the "close" command. It may not help, but it won't hurt
either) ?
As a (very) last test, what happens when you try to CopyHere a simple
textfile into the (manually) created .ZIP file ?
If that fails I'm really outof ideas I'm afraid.
.. Nope, one more: try changing.
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2,
True)
to
Set ts = fso.CreateTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip")
I just did something I should have done long before: I ran your script on my
XPsp3 machine. And after adding a "Sleep" at the end it copied a folder to
the created .ZIP file without a problem. And that means I am *really*
outof ideas.
I almost get the feeling as if something else is interfeering with the
copying process. Like an AV product perhaps ...
Regards,
Rudy Wieser
Post by Chitra Balasubramani
Post by R.Wieser
Chitra,
Post by Chitra Balasubramani
Yes Chitra is my first name :)
:-) I was asking because you adressed me by my sirname, making me wonder
if
Post by Chitra Balasubramani
Post by R.Wieser
I was talking to someone in a region where the persons own name is
written
Post by Chitra Balasubramani
Post by R.Wieser
last, and the sirname first.
Post by Chitra Balasubramani
1. Copying those files to folder instead of zip. - Worked
2. Copying files to empty zip which was created manually - Access
Denied
Post by Chitra Balasubramani
Post by R.Wieser
error.
That seems to indicate that the sourcefiles are not the problem.
Post by Chitra Balasubramani
And also if manually copy files to the same empty zip file, it is
allowing.
Post by Chitra Balasubramani
And answer to your question, after running script, Zip is empty.
That means that the (empty) ZIP file itself is of the right structure.
Could you test what happens when you try to CopyHere to a .ZIP file you
created manually (not by script) ?
If that does *not* work than I am out of ideas I'm afraid.
If it works its possible that the .ZIP file is not actually closed
before
Post by Chitra Balasubramani
Post by R.Wieser
you try to CopyHere to it. In that case putting a "sleep" between ...
Hold
Post by Chitra Balasubramani
Post by R.Wieser
the presses!
I just took another look at the code you posted, and only now noticed
something I should have much earlier: where do you *close* the .ZIP file
after you've created it ?
Try adding "ts.close" just below the "Set ts = fso.OpenTextFile(...)"
line
Post by Chitra Balasubramani
Post by R.Wieser
and see what happens.
Explanation: If the file is still open when the CopyHere command tries
to
Post by Chitra Balasubramani
Post by R.Wieser
access it (trying to open it itself) it won't work.
Hope that helps,
Regards,
Rudy Wieser
...
Post by Chitra Balasubramani
Rudy,
Yes the problem is "CopyHere" failing for the empty zip created manually.
Thanks,
Chitra
I tried the below code as well. Getting Access denied error.

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
WScript.Sleep 5000
ts.Close
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000

Set objShell = CreateObject("Shell.Application")
Set DestFldr=objShell.NameSpace("C:\apache-jmeter-3.02\bin\Results\temp.zip")
Set SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
DestFldr.CopyHere (SrcFldr.Items)
WScript.Sleep 5000

Thanks,
Chitra
R.Wieser
2016-11-30 07:53:22 UTC
Permalink
Chitra,
Post by Chitra Balasubramani
I tried the below code as well.
[snip]

I'm sorry, but I'm really outof ideas to try. And as I can't reproduce the
problem here, there is little I can do to find out why its not working at
your side.

I hope someone else has some insight to what the problem might be.

Regards,
Rudy Wieser
Post by Chitra Balasubramani
I tried the below code as well. Getting Access denied error.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
WScript.Sleep 5000
ts.Close
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set
DestFldr=objShell.NameSpace("C:\apache-jmeter-3.02\bin\Results\temp.zip")
Post by Chitra Balasubramani
Set
SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
Post by Chitra Balasubramani
DestFldr.CopyHere (SrcFldr.Items)
WScript.Sleep 5000
Thanks,
Chitra
Ulrich Möller
2016-11-30 12:53:18 UTC
Permalink
Post by Chitra Balasubramani
I tried the below code as well. Getting Access denied error.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
WScript.Sleep 5000
ts.Close
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set DestFldr=objShell.NameSpace("C:\apache-jmeter-3.02\bin\Results\temp.zip")
Set SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
DestFldr.CopyHere (SrcFldr.Items)
WScript.Sleep 5000
Hi,

may be you do have some access errors! Check each component of the
destination and source path if you have the correct rights (including
the newly created zipfile!) with the window command cacls or icalcs.

Here are some links:
http://www.robvanderwoude.com/vbstech_files_zip.php
http://www.xstandard.com/en/documentation/xzip/

Ulrich
Dave "Crash" Dummy
2016-11-29 16:56:10 UTC
Permalink
Post by Chitra Balasubramani
Hello,
I'm trying to create a zip file and copy files into it via VBS code.
Problem is Files are not getting copied, only zip file is getting created.
Set fso = CreateObject("Scripting.FileSystemObject") Set ts =
fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2,
True) ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) ) Set fso
= nothing Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application") Set
DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Set
SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
DestFldr.CopyHere SrcFldr
Thanks in advance.
I cheat. Instead of trying to use a script created zip file, I use the
freeware 7-Zip utility. Life is so much easier.

Set WshShell = CreateObject("WScript.Shell")
cmd="D:\path\7z.exe a"
DestFldr=" C:\apace-jmeter-3\bin\Results\outcome.zip"
SrcFldr=" C:\Users\chitra.balasubramani\Desktop\Mail\*.*"
ret=WshShell.Run(cmd & DestFldr & SrcFldr,0,true)
--
Crash

"Never underestimate the power of the Dark Side."
~ Obi-Wan Kenobi ~
Gloops
2016-12-19 12:40:32 UTC
Permalink
Post by Chitra Balasubramani
Hello,
I'm trying to create a zip file and copy files into it via VBS code.
Problem is Files are not getting copied, only zip file is getting created.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("C:\apace-jmeter-3\bin\Results\outcome.zip", 2, True)
ts.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
Set fso = nothing
Set ts = nothing
WScript.Sleep 5000
Set objShell = CreateObject("Shell.Application")
Set DestFldr=objShell.NameSpace("C:\apace-jmeter-3\bin\Results\outcome.zip")
Set SrcFldr=objShell.NameSpace("C:\Users\chitra.balasubramani\Desktop\Mail")
DestFldr.CopyHere SrcFldr
Thanks in advance.
Hello,

You can find an answer here :
http://stahlworks.com/dev/?tool=zipunzip

It is the same idea as 7z that Dave "Crash" Dummy points out, but with a
concurrent product, also freely downloadable.
Gloops
2016-12-19 12:42:35 UTC
Permalink
Post by Gloops
http://stahlworks.com/dev/?tool=zipunzip
My search argument was "zip command line".

Loading...