问题描述
我想编写一个bat脚本来执行以下操作:
I would like to write a bat script to do the following:
使用7 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-Zip\7z.exe" e myZipFile.zip
推荐答案
只需阅读 7z
命令的帮助键入 C:\Path To\7-Zip\7z.exe
将获得所有可能参数的帮助。在这里,我们发现以下有趣的内容:
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)
和
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%"
从帮助中: -o {Directory}:设置输出目录
。如果目录不存在,则7z将创建该目录。
From the help: -o{Directory} : set Output directory
. 7z will create the directory if it does not already exist.
这篇关于将zip内容提取到与zip文件同名的目录中,保留目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!