我应该如何重新编码包含以下命令的Windows XP cmd批处理文件,以便在以后的Windows上工作,其中两个.exes 可能位于程序文件(x86) ?
start "GW" /WAIT "%PROGRAMFILES%\GoldWave\GoldWave.exe" [...arguments...]
start "BC" /WAIT "%PROGRAMFILES%\Beyond Compare 3\BCompare.exe" [...arguments...]
这失败了:
PATH=%PATH%;%PROGRAMFILES%;%PROGRAMFILES(X86)%
...
start "GW" /WAIT "GoldWave\GoldWave.exe" [...arguments...]
start "BC" /WAIT "Beyond Compare 3\BCompare.exe" [...arguments...]
这成功但笨拙:
PATH=%PATH%;%PROGRAMFILES%\Goldwave;%PROGRAMFILES(X86)%\Goldwave;%PROGRAMFILES%\Beyond Compare 3;%PROGRAMFILES(X86)%\Beyond Compare 3%
...
start "GW" /WAIT "GoldWave.exe" [...arguments...]
start "BC" /WAIT "BCompare.exe" [...arguments...]
答案 0 :(得分:3)
您可以先查看%ProgramFiles(x86)%
是否有值。如果是,则应在该目录中找到您要查找的程序:
SETLOCAL
SET PROGRAMFILESINUSE=%ProgramFiles%
IF NOT "%ProgramFiles(x86)%"=="" SET PROGRAMFILESINUSE=%ProgramFiles(x86)%
START "GW" /WAIT "%PROGRAMFILESINUSE%\GoldWave\GoldWave.exe"
或者,您可以让它更具参与性,让它实际检查您要查找的文件的位置:
SETLOCAL
SET PROGRAMDIRECTORY=
SET RELATIVEFILEPATH=GoldWave\Goldwave.exe
CALL :CHECKFORPROGRAM "%RELATIVEFILEPATH%" "%ProgramFiles(x86)%"
CALL :CHECKFORPROGRAM "%RELATIVEFILEPATH%" "%ProgramFiles%"
IF "%PROGRAMDIRECTORY%"=="" GOTO :NOTFOUND
ECHO Found at %PROGRAMDIRECTORY%\%RELATIVEFILEPATH%
GOTO :EOF
:CHECKFORPROGRAM
IF NOT "%PROGRAMDIRECTORY%"=="" GOTO :EOF
IF EXIST "%~2\%~1" SET PROGRAMDIRECTORY=%~2
GOTO :EOF
:NOTFOUND
ECHO %RELATIVEFILEPATH% not found
GOTO :EOF