Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

batch file quesiton


  • Please log in to reply

#1
Dimension

Dimension

    Member

  • Member
  • PipPip
  • 18 posts
I am currently tinkering with a piece of code which pulls up the drives connected to my pc. this works fine however what I would like ideally is a number list of each drive which is what i'm currently trying to work out.

@echo off & setlocal enableextensions

for %%d in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do fsutil fsinfo drivetype %%d: | find /v "No such Root Directory" 

::endlocal & goto :EOF

pause

eg - it current displays:

C: - Fixed Drive
D: - CD-ROM Drive
F: - CD-ROM Drive

I would like:

1. C: - Fixed Drive
2. D: - CD-ROM Drive
3. F: - CD-ROM Drive

Please select a drive from the list:


Is this possible?
  • 0

Advertisements


#2
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Yep, it's possible. I took a little time putting this all together, you'll have to let me know if you have any questions or problems.

@echo off
setlocal enabledelayedexpansion

set tf=x
set /a number=0
for /f "tokens=1* delims= " %%a in ('fsutil fsinfo drives ^| find "\"') do call :process %%a %%b 
del %tf%

:UserInput
:: Asks for and checks user input, based on drive variables
:: If nothing is selected, processing is terminated
:: If invalid value is selected, it loops back to the beginning
set choice=
set /p choice=Please select a drive from the list:
if "%choice%"=="" Echo Exiting... & goto :eof

for /f "tokens=2 delims== " %%a in ('set drive%choice% 2^>^&1') do (
	if "%%a"=="variable" (
		Echo Invalid option selected, please try again
		goto :UserInput
	) else (
		set choice=%%a
	)
)
:: At this point, we should have a valid drive stored in the %choice% variable

endlocal
goto :eof

:process
:: Gets the information for each drive, sets the drive number variables
if "%1"=="" goto :eof
set /a number+=1
if /i "%1" NEQ "Drives:" (
	set drive%number%=%1
	fsutil fsinfo drivetype %1 > %tf%
) else (
	set drive%number%=%2
	fsutil fsinfo drivetype %2 > %tf%
)
set /p drivetype=<%tf%
echo %number%. %drivetype%

Regards,

Ax
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP