Reputation: 11
I have always tried to do this but have resorted to entering this in the command line:
CHKDSK C: /f
I tried to look up how to do it but im not that big on bat file programming and more so am just a small programmer learning java atm... I wanted to know how to do this and more so know how to compute it. As it would help me in the long term and also help me in the short term.
Would be much appreciated. :)
Upvotes: 0
Views: 729
Reputation: 4085
This script will ask the user which drive to fix, and then show a confirmation message before 'fixing' the drive:
@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
This script is easier to write and understand, but it shouldn't be used:
@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
Upvotes: 5