By default, all the zipped files in Windows 8/8.1 are configured to open with the File Explorer program that the operating system has. I want to unzip all files in a certain directory and preserve the folder names when unzipped using batch script. I know how to do this when 7-Zip installed on the machine. But how to do this on Windows 8/8.1 when no extracted software installed? I want to do this using windows script.
3 Answers
I found the way to do it using vbscript. Here is the code.
strZipFile = "" 'name of zip file
outFolder = "" 'destination folder of unzipped files
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items()
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 256
objTarget.CopyHere objSource, intOptions
Fill in the appropriate names for the zip file and the output folder (must be quoted). Save the script with a vbs extension. In the batch file we can run the script with this entry: cscript //nologo scriptname.vbs
This topic is interesting! I did several tests an discovered that after the .zip file was opened with the Explorer, I may press certain keys in order to extract the files: Alt-J and A to select "Extract all", and Enter to do that, and then Alt-F and Alt-C to close the Explorer. My Windows is 8.1 Spanish version, so I am not sure if these keys are the same for English version.
I then wrote a Batch file that use the method explained at this post to send keys to Explorer, so previous process may be achieved automatically. I had to enter some delays between the keys, otherwise the Explorer may ignore they; the delay could be a function of the .zip file size: more seconds delay on larger files.
@if (@CodeSection == @Batch) @then
@echo off
rem Start explorer with the zip file and wait for it to initialize
start "" Explorer.exe %1
timeout /T 3 > NUL
rem Send to Explorer: Alt-J, A and Enter to extract all files from .zip
CScript //nologo //E:JScript "%~F0" "%%J"
timeout /T 1 > NUL
CScript //nologo //E:JScript "%~F0" "A"
timeout /T 1 > NUL
CScript //nologo //E:JScript "%~F0" "{Enter}"
rem ... and Alt-F Alt-C to end Explorer
timeout /T 4 > NUL
CScript //nologo //E:JScript "%~F0" "%%F%%C"
echo Extracted files:
dir /p "%~N1"
goto :EOF
@end
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));