1

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.

Arun
  • 1,898
  • 3
  • 21
  • 41
  • 1
    You can't do it in plain vanilla batch commands. There is no zip/unzip utility. – foxidrive May 05 '14 at 15:53
  • For OS above XP 'compressed (zipped) folder' facility is available, where you right click folder and click 'send to' -> ''compressed (zipped) folder', a zip file will be created within that folder. Now select this zip file and right click, 'extract all' menu will be available. If you select this, wizard will open to extract file. I want this through Dos Prompt so that i can use it in my batch file – Arun May 06 '14 at 04:48

3 Answers3

1

You can check the zipjs.com utility introduced here

// unzips only part of the zip with given path inside
zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir\InzipFile -destination C:\OtherDir -keep no -force yes
zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir -destination C:\OtherDir
Community
  • 1
  • 1
npocmaka
  • 51,748
  • 17
  • 123
  • 166
0

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

Arun
  • 1,898
  • 3
  • 21
  • 41
-1

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));
Community
  • 1
  • 1
Aacini
  • 59,374
  • 12
  • 63
  • 94
  • This is a terrible idea, for a number of reasons: 1) It has hard-coded timeouts. On large files, it will likely kill explorer before the extract is finished. 2) It doesn't detect/handle errors. 3) It won't work on Server Core. 4) It potentially requires different code for every Windows language. – nobody May 05 '14 at 21:57
  • @AndrewMedico: All SendKeys examples have hard-coded delay times, like [this one](http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx). As I said in my answer, this method requires some tune-up in the keys and in the timeout as a function of the file size, but I am sure that it may solve the OP's request in a simple way. I don't understand why you prefer that the OP do this extraction manually instead... `:(` – Aacini May 06 '14 at 03:58