windows 如何使用简单的批处理文件解压并覆盖现有文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36279314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:31:30  来源:igfitidea点击:

How to use a simple batch file to unzip & overwrite existing file

windowsbatch-fileunzip

提问by suzymuse

I'm trying to use a simple batch file to unzip and overwrite an existing file. Can anyone tell me the correct parameter to use to automatically overwrite without having to intervene please?

我正在尝试使用一个简单的批处理文件来解压缩并覆盖现有文件。任何人都可以告诉我用于自动覆盖而无需干预的正确参数吗?

The unzip.bat batch file contains:

unzip.bat 批处理文件包含:

unzip "G:\Extracts\report.zip" "G:\Extracts\report\" 

This works fine except that it asks me to "Replace the file in the destination?"

这很好用,只是它要求我“替换目标中的文件?”

回答by cakan

Unzip command has -ooption, which forces file overwrite. Your batch file should look like this:

解压缩命令有-o选项,可以强制覆盖文件。您的批处理文件应如下所示:

unzip -o "G:\Extracts\report.zip" -d "G:\Extracts\report\" 

Optionally, you can add -qfor quiet mode.

或者,您可以添加-q安静模式。

回答by suzymuse

I was unable to get this to work.

我无法让它发挥作用。

Instead I used 7zip command line as follows:

相反,我使用了 7zip 命令行,如下所示:

Copied 7z.exe to the folder where my .bat file was placed.

将 7z.exe 复制到放置我的 .bat 文件的文件夹中。

Made a .bat file as follows: 7z x report.zip -o"G:\Extracts\report" -aoa

制作一个 .bat 文件如下: 7z x report.zip -o"G:\Extracts\report" -aoa

This unzipped and replaced existing files.

这解压缩并替换了现有文件。