Apagada docs

Aprendiendo a programar el pasado

Herramientas de usuario

Herramientas del sitio


en:basic:unzip_using_shell32.dll_and_cscript

Unzip using cscript and Wsh

I have no permission to run powershell in the library computer, so I can't use powershell to unzip from command line. I have to use GUI everytime I make a new backup of database and want to use access over the backup.

But I can use cscript to decompress the files via shell32.dll:

'Modified from something I saw on the net.

Sub UnZip(ExtractTo,ZipFile)
WScript.echo "Entering Unzip ("& ExtractTo &","& ZipFile &")"
Set fso = CreateObject("Scripting.FileSystemObject") 
    If NOT fso.FolderExists(ExtractTo) Then 
       fso.CreateFolder(ExtractTo) 
End If 
 
Set objShell = CreateObject("Shell.Application") 
Set FilesInZip=objShell.NameSpace(ZipFile).items 
 
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip) 
Set fso = Nothing 
Set objShell = Nothing 
End Sub
 
'Add current directory to route if needed.
'This is vital to get a valid filename we can use with nameSpace function.
Function DefaultDir (FileOrRoute , DefaultRoute )
Dim DD
	'Si el archivo contiene ":", tenemos la ruta completa.
	if instr(FileOrRoute,":")>0 then
		DefaultDir=FileOrRoute
		exit Function
	end if
	'Si el archivo comienza por "\", necesitamos la unidad
	if left (FileOrRoute,1)="\" then
		DD=Left(DefaultRoute,instr(DefaultRoute,":"))
		if right(DD,1)<>"\" then DD=DD+"\"
		DefaultDir = DD+FileOrRoute 
		exit Function
	end if
	'Caso contrario:
	'Añadir DefaultRoute entero.
	DD=DefaultRoute
	if right(DD,1)<>"\" then DD=DD+"\"
	DefaultDir = DD+FileOrRoute 
 
End Function
 
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("MyDocuments")
strCurrent=WshShell.CurrentDirectory
 
if  (Wscript.arguments.count=2) then
	strZipFile  = Wscript.arguments(0)
	strUnzipped = Wscript.arguments(1)
 
	strZipPath   = 	DefaultDir(strZipFile,strCurrent)
	strUnzipPath = 	DefaultDir(strUnzipped,strCurrent)
 
	UnZip strUnzipPath , strZipPath
else
Wscript.Echo ("Wrong number of arguments: INFILE OUTFILE")
end if
Este sitio web utiliza cookies. Al utilizar el sitio web, usted acepta almacenar cookies en su computadora. También reconoce que ha leído y entendido nuestra Política de privacidad. Si no está de acuerdo abandone el sitio web.Más información
en/basic/unzip_using_shell32.dll_and_cscript.txt · Última modificación: 2017/11/14 16:53 por nepenthes