Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in VbScript , and i want to vbscript which will copy zip file and extract it.

i have used this code
VB
Sub ExtractFile(objFSO,lastImportDate,zipFilePath)
        DIM subFolderPath
	subFolderPath = "\developer\"
	DIM dumpFile
	dumpFile = "fichero.dump"
	Dim extractTo
	extractTo = "C:\DB importer - Copy\\db-backup-" 
	
	extractTo = extractTo + lastImportDate

	'If the extraction location does not exist create it.
	Set fso = CreateObject("Scripting.FileSystemObject")
	If NOT fso.FolderExists(extractTo) Then
	   fso.CreateFolder(extractTo)
	End If

	'Extract the contants of the zip file.
	set objShell = CreateObject("Shell.Application")
	set FilesInZip=objShell.NameSpace(zipFilePath).items //error
	objShell.NameSpace(extractTo).CopyHere(FilesInZip)
	Set fso = Nothing
	Set objShell = Nothing
End Sub


but its giving error at // error
Object required: 'objShell.NameSpace(...)'

This vbscript should run on any pc.

If any have solution , reply as soon as possible.
Thank you.
Posted

view this link for reference Easily-zip-unzip-files
 
Share this answer
 
Comments
Thank you for reply.
I have folder called TestFolder in that i have test.vbs and AbcFolder and in AbcFolder i have zipFile.zip.
When i run the .vbs file from desktop and did not set the path for
"extractTo" eg This will be run on any pc , so this file will be run from any where so just wrote extractTo = AbcFolder\zipFile.zip
so when i run it from desktop its run and create folder called zipFile in AbcFolder but not copying contain of .zip file and giving same error as i got before
Object required: 'objShell.NameSpace(...)'.
If you have any other solution let me know.
Thank you.
XML
Here i just do these
<pre lang="vb">
Dim objShell
set objShell = CreateObject("Shell.Application")
objShell.NameSpace(extractTo).CopyHere objShell.NameSpace(extractFrom).Items
</pre>

instead of these
<pre lang="vb">
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(zipFilePath).items //error
objShell.NameSpace(extractTo).CopyHere(FilesInZip)
</pre>

and add "\" in extractTo path.
Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900