将 zip 内容解压到与 zip 文件同名的目录中,保留目录结构 [英] Extract zip contents into directory with same name as zip file, retain directory structure

查看:77
本文介绍了将 zip 内容解压到与 zip 文件同名的目录中,保留目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个bat脚本来做以下事情:

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

使用 7 Zip 将文件从现有 zip 文件中提取到与原始 zip 文件同名的文件夹中(禁止 .zip 扩展名),并保留该文件 &zip 文件中包含的目录结构.

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.

我可以使用

"C:Program Files (x86)7-Zip7z.exe" e  myZipFile.zip

推荐答案

只需键入 "C:Path To7-Zip7z,即可阅读 7z-命令的帮助.exe" 获取所有可能参数的帮助.在这里,我们发现了以下有趣的内容:

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

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

x : eXtract files with full paths

反复试验表明,后者是一种无需付出更大努力即可满足您所需行为的方法:)

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

@BadmintonCat 发表评论之后,这里添加了一个将创建一个文件夹以将所有内容压缩到其中(用作批处理以文件为参数的脚本):

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%"

来自帮助:-o{Directory}:设置输出目录.如果目录不存在,7z 将创建该目录.

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

这篇关于将 zip 内容解压到与 zip 文件同名的目录中,保留目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆