Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting drives and drive types

36 views
Skip to first unread message

John Clavin

unread,
Feb 8, 2003, 11:04:25 PM2/8/03
to
I want to detect from a batch file what drives are connected to a
WinXP system. I thought about building a parser based on the
following construct to locate active drives:

for /f "tokens=2" %%i in ('fsutil fsinfo drives') do set j=%%i

and then using another parser based on the following to determine
what type of drive each was:

for /f "tokens=3" %%i in ('fsutil fsinfo drivetype %j%') do set k=%%i

The problem is that 'fsutil fsinfo drives" returns a string such as:
Drives: A:\ C:\ D:\ E:\ M:\ N:\

but where the "spaces" are actually nul characters. These causes the
FOR statement to be unable to read tokens past the first nul.

Any ideas?

Ritchie

unread,
Feb 9, 2003, 9:29:27 AM2/9/03
to
"John Clavin" <j...@austin.rr.com> wrote in message
news:Xns931CE08D4...@24.28.95.150...

> The problem is that 'fsutil fsinfo drives" returns a string such as:
> Drives: A:\ C:\ D:\ E:\ M:\ N:\
>
> but where the "spaces" are actually nul characters. These causes the
> FOR statement to be unable to read tokens past the first nul.

The thing to do here is pipe the output through another command, such
as MORE, which effectively regards the NUL character as CR/LF. For
instance, this command:-

fsutil fsinfo drives|more

Gives an output like this:-

Drives: A:\
C:\
D:\
E:\
M:\
N:\

Then pass each line your 'fsutil fsinfo drivetype' command. Only trouble is,
you need to lose the string 'Drives: '. One way of doing this is to use a
space as a delimiter and then reverse the tokens and use the first. For
example:-

for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
for /f "tokens=1" %%c in ('echo/%%b %%a') do fsutil fsinfo drivetype %%c
)

--
Ritchie
Anyone know what kind of idiot decided to have FSUTIL separate drive letters
with NULs?


Pavel Srubar

unread,
Feb 10, 2003, 12:11:39 PM2/10/03
to
"Ritchie" <qiournvdlirh...@hotmail.com> wrote
> Anyone know what kind of idiot decided to have FSUTIL separate
> drive letters with NULs?

It was brother of another idiot who decided FSUTIL output messages
be translated in localized versions of WinXP. Now we need different
version of the parsing script for each national version of Windows.

Bye,
v
Sr.

guard

unread,
Feb 17, 2003, 10:03:07 AM2/17/03
to
The (FREE) Advanced NT Command Library (ntlib.cmd) provides the
.Mount/\Command %.ListCD%, which lists the current directory of all local
and remote drives [C-Z] under NT/2K/XP/K3 using only what is available in a
standard install of each platform.
*******
C:\>%.ListCD%
C:\winnt
D:\
E:\
M:\
N:\
*******
To use this in a FOR loop, you need the "escapified" version, %.eListCD%.

C:\>FOR /F "delims=\" %A IN ('%.eListCD%') DO @ECHO:%A
C:
D:
T:

C:\>FOR /F "delims=:\" %A IN ('%.eListCD%') DO @ECHO:%A
C
D
T

*******
The .ListCD page is at
(http://TheSystemGuard.com/MtCmds/ListValue/ListCD.htm)
*******
Notes:

1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. ntlib.cmd provides over 100 resources to assist with
writing and documenting cross-platform scripts,
including 57 .M/\C's. You can obtain it (for FREE)
at http://ntlib.com.

*******

TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-coded page, highlighting the differences
among the NT/2K/XP/K3 versions. The complete help text for each OS is also
available for comparison (http://TheSystemGuard.com/TheGuardBook/CCS-Int.)

*******

-tsg
____________________________________________________________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!

"John Clavin" <j...@austin.rr.com> wrote in message
news:Xns931CE08D4...@24.28.95.150...

0 new messages