使用批处理解压缩和重命名文件 (Windows) [英] Unzip and rename files with a batch (Windows)

查看:55
本文介绍了使用批处理解压缩和重命名文件 (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天全站免登陆