Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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