如何编写可以解压缩文件到一个新的文件夹具有相同名称的批处理文件? [英] How to write a batch file that can unzip a file into a new folder with the same name?

查看:223
本文介绍了如何编写可以解压缩文件到一个新的文件夹具有相同名称的批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写一个批处理脚本,让我解压的.zip文件到具有相同名称的压缩文件的新文件夹。我不认为我有一些程序解压缩文件;它仿佛电脑是全新的工作。

I need to write a batch script that will allow me to unzip a .zip file into a new folder that has the same name as the zip file. I cannot assume that I have some program to unzip the file; it has to work as if the computer is brand new.

例如,如果我有一组命名为A1,B2,C3,D4和zip文件,我想它们的内容进入标有A1,B2,C3,D4 4种不同的文件夹中。它并不需要是简洁,它只是工作。

For example, if I have a group of zip files named a1, b2, c3, and d4, I want their contents to go into 4 different folders labeled a1, b2, c3, d4. It doesn't need to be concise, it just has to work.

推荐答案

阅读优秀的话题我怎样才能融为一体preSS(ZIP )和uncom preSS(解压缩)文件和批处理文件的文件夹,而无需使用任何外部工具?通过 npocmaka <写/ A>

Read excellent topic How can I compress (zip) and uncompress (unzip) files and folders with batch file without using any external tools? written by npocmaka.

我建议使用第二种方案:使用Shell.Application

I suggest to use the second solution: Using Shell.Application

任务可以 zipjs.bat <完成/ A>还写了 npocmaka 用短短几行的批处理文件:

The task can be done with zipjs.bat also written by npocmaka with a batch file with just a few lines:

@echo off
for %%I in (*.zip) do call "%~dp0zipjs.bat" unzip -source "%%~fI" -destination "%%~dpnI\" -force yes
for /F "delims=" %%D in ('dir /AD /B "%TEMP%\*.zip" 2^>nul') do (
    %SystemRoot%\System32\attrib.exe -h "%TEMP%\%%~D"
    rd /S /Q "%TEMP%\%%~D" 2>nul
)

混合批处理文件 zipjs.bat 必须在同一文件夹中与上述两行的批处理文件。

The hybrid batch file zipjs.bat must be in same folder as the batch file with the two lines above.

运行在命令提示符窗口呼叫/?解释%〜DP0 这意味着参数0的驱动器和路径的批处理文件,而不周围用反斜杠总是结束引号。一个称为批处理文件的参数0是批处理文件的名称,亦见是什么%〜DP0的意思,它是如何工作的?

Running in a command prompt window call /? explains %~dp0 which means drive and path of argument 0 of batch file without surrounding quotes ending always with a backslash. Argument 0 of a called batch file is the name of the batch file, see also What does %~dp0 mean, and how does it work?

命令的帮助在命令提示符窗口中运行显示为/?解释

Help of command for displayed on running in a command prompt window for /? explains


  • %%〜FI - 完整的文件/文件夹名,而不周围的引号,和

  • %%〜DPNI - 驱动器,没有周围的引号和不带扩展名的文件/文件夹的路径和名称

  • %%~fI - full file/folder name without surrounding quotes, and
  • %%~dpnI - drive, path and name of a file/folder without surrounding quotes and without extension

对于像循环变量呼叫/?确实为批处理参数/参数。

for loop variables like call /? does for batch parameters/arguments.

第二个循环中找到临时文件目录中所有子目录与 .zip文件目录名,删除隐藏属性,并删除这些子目录。这是必要的,因为 zipjs.bat 首先提取每个文件到临时文件目录的新创建子目录,成功提取后离开他们那里。

The second for loop finds all subdirectories in directory for temporary files with .zip in directory name, removes the hidden attribute and deletes those subdirectories. This is necessary as zipjs.bat first extracts each file into a newly created subdirectory in directory for temporary files and leaves them there after successful extraction.

这篇关于如何编写可以解压缩文件到一个新的文件夹具有相同名称的批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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