Extract zip contents into directory with same name as zip file, retain directory structure

佐手、 提交于 2019-12-23 02:32:33

问题


I would like to write a bat script to do the following:

Use 7 Zip to extract files from an existing zip file, into a folder by the same name as the original zip file (bar the .zip extension), and keeping the file & directory structure that was contained in the zip file.

I can extract all the same files into the current directory, by using

"C:\Program Files (x86)\7-Zip\7z.exe" e  myZipFile.zip

回答1:


Reading the help of the 7z-command by just typing "C:\Path To\7-Zip\7z.exe" gets the help with all possible arguments. Here we find the following interesting ones:

 e : Extract files from archive (without using directory names)

and

x : eXtract files with full paths

Trial and error shows that the latter is the one fitting your desired behaviour without bigger effort :)

After the comment by @BadmintonCat here is the addition that will create a folder to zip everything into (use as batch script with the file as argument):

@echo off

SET "filename=%~1"
SET dirName=%filename:~0,-4%

7z x -o"%dirName%" "%filename%"

From the help: -o{Directory} : set Output directory. 7z will create the directory if it does not already exist.



来源:https://stackoverflow.com/questions/41932553/extract-zip-contents-into-directory-with-same-name-as-zip-file-retain-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!