2016-01-25 46 views
0

我似乎無法找出這一個,這是一個相當簡單的腳本。我的if語句不檢查文件是否存在,else命令沒有在appdata目錄中創建文件。批處理文件未能創建txt文件

reg.exe工作正常,已添加密鑰。

任何指導都會很棒。

@echo 
IF EXIST "%APPDATA%\outlookclean.txt" (exit 
) 
else 
( 
% reg.exe add HKCU\Software\Microsoft\Office\15.0\Outlook\Profiles\OutlookTest 
@echo Done > "%APPDATA%\outlookclean.text" 
) 

回答

0

的語法是非常具體的。 else及其前後括號都必須與空格在同一條物理線上。

適用於括號exit太前...

@echo 
IF EXIST "%APPDATA%\outlookclean.txt" (exit 
) else ( 
% reg.exe add HKCU\Software\Microsoft\Office\15.0\Outlook\Profiles\OutlookTest 
@echo Done > "%APPDATA%\outlookclean.text" 
) 

不知道爲什麼你的reg.exe行開始% - 即不應該存在。

+0

啊,這很合理!這沒有竅門,謝謝! –

0

做舊help if會給你一個強烈的暗示什麼可能是你的代碼錯誤:

按照therefound文檔中,else命令必須是在同一行if命令,因爲批次是一種可怕的語言,所以你的代碼應該看起來像這樣:

@echo off REM did you want to turn the output off? 
IF EXIST "%APPDATA%\outlookclean.txt" (exit 
) else (
REM notice the else being between the parenthesis? yeah, batch is terrible 
REM also whats the deal with the % at th start of the next line? 
reg.exe add HKCU\Software\Microsoft\Office\15.0\Outlook\Profiles\OutlookTest 
@echo Done > "%APPDATA%\outlookclean.text" 
)