2012-06-08 96 views
1

我有以下腳本來執行當前目錄中的所有.reg文件。問題是我也有該目錄中的子目錄,我也想執行這些reg文件。我不知道我應該使用什麼開關。我嘗試使用/s,它返回驅動器的所有.reg文件。執行批處理文件中的所有.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 

我失去了什麼嗎?

回答

1

我認爲你需要使用/R開關遞歸for循環:

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

他會需要'SETLOCAL enabledelayedexpansion' –

+1

其實也沒什麼,除非他想以某種方式操縱'%% i'並改變其值_inside_循環。 –

+0

是的,你是對的,它不適合我,但只是因爲我犯了一個錯字 –

0

你實際上並沒有說你的問題是什麼,所以不是在這裏修理你的劇本是我會做:

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

而註冊表中的/s腳本是用於靜默模式的。它告訴regedit不要讓用戶通過對話框進行確認。 for循環是導致批處理文件遍歷所有子目錄的原因,而不是在regedit上的/s開關。

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.