iT邦幫忙

0

請教bat 參數 與 if 用法

bat
匿名 2014-10-01 17:42:2620460 瀏覽
  • 分享至 

  • xImage

執行bat時,想輸入數字來判別說要開啟哪個資料夾,
請問該如何寫呢?
有嘗試一下,但不太熟悉,望請指教。

set /p %1="請輸入"
if %1% == a  goto test1
if %1% == b  goto test2
if %1% == c  goto test3
:test1
echo 開啟(a資料夾)
start G:\a資料夾\
exit
:test2
echo 開啟(b資料夾)
start G:\b資料夾\
exit
:test3
echo 開啟(c資料夾)
start G:\c資料夾\
exit

pause
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

16
蟹老闆
iT邦大師 1 級 ‧ 2014-10-01 19:59:25
最佳解答

如果使用IF會使得批次檔變複雜,直接用GOTO比較簡潔

<pre class="c" name="code">
@ECHO off
set /p AA=輸入代號:
goto %AA% 
:1
echo 111
goto :eof
:2
echo 222
goto :eof
:3
echo 333
goto :eof
:4
echo 444
goto :eof
:5
echo 555
goto :eof
0
baby900519
iT邦新手 5 級 ‧ 2014-10-03 09:19:43

開啟資料夾 用 explorer d:\foldername
詳參http://support.microsoft.com/kb/130510/zh-tw

我要發表回答

立即登入回答