2016-09-26 19 views
0

我一直都在做,但都使出在命令行中輸入如下:如何製作一個bat文件,詢問用戶他們想要修復的驅動器?

CHKDSK C: /f 

我試圖查找如何做到這一點,但即時通訊上的bat文件編程並不大,更何況我只是一個小程序員學習java atm ... 我想知道如何做到這一點,所以知道如何計算它。因爲這會對我有長遠的幫助,並在短期內對我有所幫助。

將不勝感激。 :)

+4

可能的重複[在Windows cmd中,如何提示用戶輸入並在另一個命令中使用結果?](http://stackoverflow.com/questions/1223721/in-windows-cmd-how-我也可以看看這個==> [我怎樣才能得到一個CHKDSK的結果,運行結果在另一個com中] –

+0

在開機?](http://stackoverflow.com/questions/38504689/how-can-i-get-the-results-of-a-chkdsk-that-run-on-boot) – Hackoo

回答

5

使用的選擇/ C'命令

該腳本將詢問哪個驅動器以固定用戶,然後顯示之前「固定」的驅動器的確認消息:

@echo off 
:start 
    setlocal EnableDelayedExpansion 
    set letters= abcdefghijklmnopqrstuvwxyz 
    choice /n /c %letters% /m "Please enter the drive letter you would like to fix: " 
    set drv=!letters:~%errorlevel%,1! 
    echo Are you sure... to fix %drv%:\? 
    choice 
    if errorlevel 2 goto :start 
    chkdsk %drv%: /f 
    echo Complete! 
pause 


使用「設置/ p」命令

這個腳本更容易編寫和理解,但不應該被使用:

@echo off 
:start 
:: Clears the contents of the %drv% variable, if it's already set 
    set "drv=" 
:: Queries the user for input 
    set /p "drv=Please enter the drive letter you would like to fix: " 
:: Check if input was blank 
    if "%drv%"=="" echo Don't leave this blank&goto :start 
:: Check if input contained more then 1 letter (Doesn't account for numbers or special characters) 
    if not "%drv:~1,1%"=="" echo Please enter the drive letter&goto :start 

    echo Are you sure you want to fix %drv%:\? 
    choice 
    if errorlevel 2 goto :start 
    chkdsk %drv%: /f 
    echo Complete! 
    pause 
+0

嘗試該程序,並獲得錯誤,它告訴我: 無法打開直接訪問的卷。 完成! 按任意鍵繼續。 。 。 – GugiD

+3

這種類型的代碼(使用'choice'的代碼)是許多人認爲批處理文件不夠簡單和粗糙的原因。一個較短的等價物將是:'setlocal EnableDelayedExpansion'&'set letters = abcdefghijklmnopqrstuvwxyz'&'choice/n/c%letters%/ m「Please ...:''&'set drv =!letters:〜%errorlevel%, 1&''&'echo你確定...'等等... – Aacini

相關問題