如何制作一个bat文件,要求用户提供他们想要修复的驱动器?

时间:2016-09-26 19:11:14

标签: batch-file cmd command

我一直试图这样做,但已经在命令行中输入了这个:

CHKDSK C: /f

我试着查看如何做到这一点,但我对bat文件编程并不是那么大,所以我只是一个学习java atm的小程序员... 我想知道如何做到这一点,所以知道如何计算它。因为它可以长期帮助我,并在短期内帮助我。

非常感谢。 :)

1 个答案:

答案 0 :(得分:5)

使用' choice / 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