【问题标题】:Unzip and rename files with a batch (Windows)使用批处理解压缩和重命名文件 (Windows)
【发布时间】:2017-08-10 22:34:42
【问题描述】:

我是批处理文件的新手,我的代码有些问题。我已经调查了此页面的其他问题,但仍然无法完成我的任务。我在同一个目录中有多个压缩文件夹,每个文件夹中有一个 .html 文件。我需要解压缩文件夹并用文件夹名称重命名 .html。

例子:

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

【问题讨论】:

  • 我不能了解ren 命令如何给出FolderA.zip with file xyz.html 结果?你能解释更多吗?

标签: batch-file archive


【解决方案1】:
  • 迭代 html 文件的 for 循环变量是 %%f 而不是 %%I
  • 您还需要delayed expansion 设置并使用 (代码块)中的变量。
  • 修改器~na 将返回名称和属性?

@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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多