批量解压缩并重命名文件(Windows) [英] Unzip and rename files with a batch (Windows)

查看:66
本文介绍了批量解压缩并重命名文件(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在批处理文件方面还很陌生,我的代码也遇到了一些麻烦.我曾在此页的其他问题中进行过调查,但仍然无法完成任务.我在同一目录中有多个压缩文件夹,每个文件夹中都有一个.html文件.我需要解压缩文件夹,然后使用文件夹名称重命名.html.

I'm very new at batch files and have some troubles with my code. I had investigated in other questions of this page but can't still do my task. I have multiples zipped folders in the same directory with an .html file inside each one. I need to unzip the folders and rename the .html with the name of the folder.

示例:

FolderA.zip with file xyz.html
FolderB.zip with file abc.html

结果:

file FolderA.html
file FolderB.html

这是我的代码:

cd C:\Users\MyUser\Desktop
for /F %%I IN ('dir /b /s *.zip *.rar') DO (
set nombre2=%%~naI
"C:\Program Files\7-Zip\7z.exe" x -o"%%~dpI" "%%I" -aoa
for /F "delims=" %%f in ('dir /a-d /b *.html') do (
ren %%I %nombre2%.html
 ) 
)
DEL *.zip

推荐答案

  • 迭代html文件的for循环变量是 %% f 而不是 %% I .
  • 您还需要已延迟扩展设置并使用(代码块中)变量.
  • 修饰符〜na 将返回名称和属性?
    • The for loop variable iterating the html files is %%f not %%I.
    • You would also need delayed expansion setting and using a variable in a (code block).
    • The modfiers ~na will return name and attributes?
    • @Echo off
      cd C:\Users\MyUser\Desktop
      for /F %%I IN ('dir /b /s *.zip *.rar') DO (
           "C:\Program Files\7-Zip\7z.exe" x -o"%%~dpI" "%%I" -aoa
          for /F "delims=" %%f in ('dir /a-d /b *.html') do (
              ren ""%%f" "%%~nI.html"
          ) 
      )
      DEL *.zip
      

      这篇关于批量解压缩并重命名文件(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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