(cmd) How to unzip files from a . zip by Windows cmd

Asked

Viewed 7,988 times

1

I need help to unzip files . mdf and . ldf which is in a single file . zip, need to do this by Windows cmd.

  • If you use 7zip this video can help you https://www.youtube.com/watch?v=XLMJgnVKkFE. The guy tells you to download the file from this link (http://www.7-zip.org/) and remove the executable and the .dll to work for the CMD.

  • Good evening, it has how to do via bat hybrid c VBS, you have interest in the solution? Basically eh a bat q generates a VBS to perform file unzipping.

  • Yes, I have an interest

2 answers

1



Update added support for passage argument [%~1] argument [%~2]


Un_Zipper.cmd %~1         %~2
Un_Zipper.cmd Arquivo.Zip Dive+\Pasta-DestinoX para descompactar Arquivo.Zip 

Use with "parameter/argument" to point the destination folder to decompression

Un_Zipper.cmd "arquivo.zip" "c:\Pasta_de_destino"


inserir a descrição da imagem aqui


If %~2 is not informed, it unzip in the folder "%temp% Zip_name sem_extension"

I believe it’s good for you to edit so you can handle the files/folders for their respective destinations post-decompression...


Un_Zipper.cmd


@echo off & setlocal enabledelayedexpansion & title 

color 9F & cls & cd /d "%~dp0" & mode 60,7 & set "_pping=pathping 127.1 -q 1 -p 100" & title <nul

if /i ".%~1/"=="./" set "_msg_err_= Use: %~nx0 Arquivo.Zip "c:\Pasta-destino" # Arquivo.Zip nao Informado ou Invalido " && goto :_3rr0_msg_:
if /i not "%~x1"==".zip" set "_msg_err_= Arquivo: %~nx1 Nao eh Valido # Use: %~nx0 Arquivo.Zip "c:\Pasta de destino"" && goto :_3rr0_msg_:
if /i ".%~2/"=="./" (set "_target_dir=%temp%\%~n1") else (set "_target_dir=%~2" & if not exist "%~2\" mkdir "%~2" || goto :_3rr0_msg_:)

if /i "!_msg_err_!./"=="./" set "_vbs_Un_Zipper_=%temp%\Un_Zipper.vbs" & type nul>"!_vbs_Un_Zipper_!"
set "_zip_File_=%~nx1" & set "_Zip_Folder_=!_target_dir!" & if /i not "!_Zip_File_:~-3!"=="zip" goto :_3rr0_msg_:
set "_Run_wScript_=start "" /w "%Windir%\System32\wscript.exe" "!_vbs_Un_Zipper_!" //nologo"

(rmdir /q /s "!_Zip_Folder_!" & !_pping! && mkdir "!_Zip_Folder_!" || mkdir "!_Zip_Folder_!") 2>nul >nul
!_pping! >nul && copy /y "%~f1" "!_Zip_Folder_!\!_zip_File_!" >nul & set "_Zip_File_=!_Zip_Folder_!\!_zip_File_!"

set _Zip_File=!_Zip_Folder_!\!_zip_File_!" & dir "!_Zip_Folder_!\*.zip" /b >nul 2>nul || >nul (
set _msg_err_= ERRO: Nao Encontrado !_zip_File_! " & goto :_3rr0_msg_:)

call :_write_vbs_: & !_pping! >nul & echo/ & echo/ & echo/  Descompactando: %~nx1... & !_Run_wScript_!
if "!%errorlevel%!" == "!0!" goto :eof || set "_msg_err_=Erro: Verique !_Zip_Folder_!\%~nx1 " & goto :_3rr0_msg_:

:_write_vbs_:

>"!_vbs_Un_Zipper_!"^
   (
     echo/ ZipFile = "!_zip_File_!" : ExtractTo = "!_Zip_Folder_!\" : Set ObjShell = CreateObject^("Shell.Application"^)
     echo/ Set FilesInZip=ObjShell.NameSpace^(ZipFile^).items: Set FSO = CreateObject^("Scripting.FileSystemObject"^)
     echo/ ObjShell.NameSpace^(ExtractTo^).CopyHere^(FilesInZip^): Set FSO = Nothing: Set ObjShell = Nothing
   ) && exit /b || set "_msg_err_=Erro: Verifique: "!_Zip_File_!"

:_3rr0_msg_:

if "/!_msg_err_!" == "/" set "_msg_err_= Pasta informada de destino eh invalida^!!" & mode 099,007
color F4 & cls & echo/ & echo/ ERRO^^!! & for /f %%a in ('echo prompt $h ^| cmd')do set "_bs=%%a"
for /f delims^=^ eol^= %%a in ('"(cmd /u /c echo=!_msg_err_!) |find /v """')do !_pping! >nul & set/p "=-!_bs!%%a"<nul
!_pping! >nul & set /p "= ^! %_bs%"%_bs% <nul & timeout /t 5 >nul & echo/ & color 0a & exit /b

  • Code VBS without the scaping:

ZipFile = "!_zip_File_!"
ExtractTo = "!_Zip_Folder_!\"
Set ObjShell = CreateObject("Shell.Application")
Set FilesInZip=ObjShell.NameSpace(ZipFile).items
Set FSO = CreateObject("Scripting.FileSystemObject")
ObjShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set FSO = Nothing: Set ObjShell = Nothing


  • 1

    What a top! It was very good your tip and the code. Excuse my ignorance regarding the use of bat, I never made a file .bat. Shall I put the file name .zip on the code line echo/ ZipFile = "!_zip_File_!" replacing by the name of my file without the .zip? Where I point out the way to my zip file?

  • I get it, thank you!

  • @Ronisonmatos can be passed via Command or Drag and Drop. Un_zipper.CMD.zip file with the path in quotes when you have space in the file/folder name.

  • 1

    Open cmd.exe and then call Un_zipper.cmd if you do not pass any zip file name. You will receive a message from ERROR simulating a typing, and containing information (little).

  • 1

    It worked exactly as you mentioned! Thank you very much!

1

I believe that you can only extract a file this way, by CMD, if you have some program that does this.

In the case of Winrar, for example, you can run this command on your CMD, to unzip the file and send to the desired location for extraction:

C:\Program Files\WinRAR>winrar x C:\temp\seu_arquivo.zip C:\seu_caminho\

Browser other questions tagged

You are not signed in. Login or sign up in order to post.