2013-06-25 49 views
1

我一直在處理這個腳本一點,我是新的編寫批處理文件。我知道我的語法錯了,需要一些幫助。批處理的語法問題

@echo off 
setlocal enabledelayedexpansion 
set "ports=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" 
for /f %%I in ('reg query "%ports%"') 
do (
    echo %%I | findstr /i "c:\\convertdoc\\output\\silentprinttemp\\.*\.ps" >NUL 
    IF ERRORLEVEL 1 reg delete "%ports%" /v "%%I" /f  
) 
+0

我還是從代碼收到一個錯誤。 –

+0

嘗試用'for/f「delims =」%%我在('reg query'%ports%''') – npocmaka

+0

這對我不起作用@npocmaka –

回答

2
@echo off 
setlocal 
set "ports=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" 
for /f %%I in ( 
    'reg query "%ports%"' 
     ) do (
    echo %%I | findstr /i "c:\\convertdoc\\output\\silentprinttemp\\.*\.ps" >NUL 
    IF ERRORLEVEL 1 reg delete "%ports%" /v "%%I" /f  
) 
+0

這個工作除了它刪除所有內容只是它找到的字符串@captcha。我有一堆行是c:\\ convertdoc \\ output \\ silentprinttemp \\。* \。ps,我試圖刪除,但它也是刪除像FILE:,LPT1等的東西。 –

+0

對不起。我需要如果不是。 –

1

正如評論中指出的那樣,cmd希望在與前一個表達式的右括號相同的行上做「do」。你沒有使用延遲擴展。這不是一個錯誤,但我沒有理由打開它。

@echo off 
setlocal 
set "ports=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" 
for /f %%I in ('reg query "%ports%"') do (
    echo %%I | findstr /i "c:\\convertdoc\\output\\silentprinttemp\\.*\.ps" >NUL 
    IF ERRORLEVEL 1 reg delete "%ports%" /v "%%I" /f  
) 

奇怪的是,這個實驗的工作:

FOR /F %%i IN (
'dir /b' 
) DO (
@ECHO %%i 
)