1

I have following script that executes all the .reg files in the current directory. the problem is i also have sub directories in that folder and i want to execute those reg files as well. I am not sure what switch i am supposed to use. i tries using /s which returns all the .reg files of the drive.

this is how my batch file looks like:

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

This is how file/directory structure looks like:

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

what am i missing here?

4

2 回答 2

2

I think that you need a recursive for loop using the /R switch:

for /R "%folder%" %%i in (*.reg) do (regedit /s "%%i")
于 2012-06-08T18:37:04.133 回答
0

You didn't actually say what your problem was, so instead of fixing your script here's what I would have done:

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

And the /s script on regedit is for silent mode. It tells regedit not to ask the user for confirmation with a dialog box. The for loop is what causes the batch file to loop through all subdirectories, not the /s switch on regedit.

From 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.
于 2012-06-08T18:37:47.710 回答