【问题标题】:executing all the .reg files from batch file从批处理文件执行所有 .reg 文件
【发布时间】:2012-06-08 16:31:32
【问题描述】:

我有以下脚本执行当前目录中的所有 .reg 文件。问题是我在该文件夹中也有子目录,我也想执行这些 reg 文件。我不确定我应该使用什么开关。我尝试使用 /s 返回驱动器的所有 .reg 文件。

这就是我的批处理文件的样子:

rem @echo off
cls
SET folder=%~dp0
for %%i in ("%folder%*.reg") do (regedit /s "%%i")
echo done
pause
EXIT

这是文件/目录结构的样子:

Folder1
   batchfile.bat -> user double clicks or executes from command prompt
   1.reg
   2.reg
   3.reg
   Folder2
      4.reg
      5.reg

我在这里错过了什么?

【问题讨论】:

    标签: batch-file batch-processing


    【解决方案1】:

    我认为您需要使用 /R 开关的递归 for 循环:

    for /R "%folder%" %%i in (*.reg) do (regedit /s "%%i")
    

    【讨论】:

    • 他还需要setlocal enabledelayedexpansion
    • 实际上没有,除非他想以某种方式操纵%%i 并在循环内部更改其值。
    • 是的,你是对的,它对我不起作用,只是因为我打错了
    【解决方案2】:

    你实际上并没有说你的问题是什么,所以我不会在这里修复你的脚本:

    @echo off
    set folder=%~dp0
    for /f "usebackq" %%i in (`dir /s /b *.reg`) do (
            regedit /s "%%i"
    )
    

    regedit 上的/s 脚本用于静默模式。它告诉 regedit 不要通过对话框要求用户确认。 for 循环是导致批处理文件循环遍历所有子目录的原因,而不是 /s regedit 上的开关。

    来自Microsoft's Knowledge Base:

    [/s|-s]
    When a filename is specified on the command line, this switch is used to 
    suppress any informational dialog boxes that would normally be displayed.
    This is useful when the Setup program for an application wants to execute
    REGEDIT.EXE with a .REG file, but does not want the user to be confused by
    any dialog boxes that are displayed.
    

    【讨论】:

      猜你喜欢
      • 2014-01-01
      • 2022-01-17
      • 2016-12-10
      • 1970-01-01
      • 2016-09-09
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      相关资源
      最近更新 更多