#1 01 Mar 2008 14:59

budhax
Member
Registered: 04 Dec 2007
Posts: 45

How to slice the output of: FSUTIL FSINFO DRIVES

Hello,
this command: FSUTIL FSINFO DRIVES
outputs something like:

Drives: A:\ C:\ D:\

1. How to get drives list, one by line?

A:\
C:\
D:\

2. How to get "Drives: A:\ C:\ D:\" in a variable's value?
Thank in advance.

Offline

#2 02 Mar 2008 16:36

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

That was a little more challenging that I expected, due to some weirdness with the output produced by FSUTIL (contrary to how it might appear, those aren't spaces between the items in the list.)  Nevertheless, I worked around it, this should do what you ask on both counts (tested on WinXP only):

@echo off
setlocal enabledelayedexpansion
set drives=
for /f "usebackq tokens=1*" %%a in (`FSUTIL FSINFO DRIVES ^| find ":"`) do (
    if /i "%%a" NEQ "Drives:" (
        set "drives=!drives! %%a"
        echo:%%a
    ) ELSE (
        set "drives=!drives! %%b"
        echo:%%b
    )
)

set drives=%drives:~1%
echo:"%drives%"

pause

Last edited by bluesxman (02 Mar 2008 16:38)


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#3 23 May 2009 05:15

blufr0g
Member
Registered: 23 May 2009
Posts: 1

Re: How to slice the output of: FSUTIL FSINFO DRIVES

This works but then you end up with "Drives:" as one of the outputs, which doesn't really matter if you are passing the variable through some command it will just fail and move to the next actual drive:

FOR /F "usebackq tokens=1" %%x IN (`FSUTIL FSINFO DRIVES ^| FIND ":"`) DO @ECHO %%x

This runs twice as fast as the fsutil approach and most importantly does not output "Drives:"

FOR /F "usebackq tokens=1" %%x IN (`MOUNTVOL ^| FIND ":\"`) DO @ECHO %%x

Working examples, output removable drive letters:

FOR /F "usebackq tokens=1" %%a IN (`FSUTIL FSINFO DRIVES ^| FIND ":"`) DO (
FOR /F "usebackq tokens=3" %%b IN (`FSUTIL FSINFO DRIVETYPE %%a`) DO (
IF /I "%%b" EQU "Removable" ECHO %%a ))

or better yet:

FOR /F "usebackq tokens=1" %%a IN (`MOUNTVOL ^| FIND ":\"`) DO (
FOR /F "usebackq tokens=3" %%b IN (`FSUTIL FSINFO DRIVETYPE %%a`) DO (
IF /I "%%b" EQU "Removable" ECHO %%a ))

Offline

#4 24 May 2009 03:16

avery_larry
Member
Registered: 11 Jul 2007
Posts: 266

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Offline

#5 24 May 2009 07:40

*SCRIPTER*
Member
Registered: 17 Mar 2009
Posts: 48
Website

Re: How to slice the output of: FSUTIL FSINFO DRIVES

To achieve the desired format you might want to try this . . .

for /f "skip=1 tokens=*" %a in ('wmic logicaldisk get deviceid') do @echo %a

Last edited by *SCRIPTER* (24 May 2009 07:47)


Batch files are the cancer we die with not of.

Offline

#6 27 May 2009 04:53

Leo_Gutierrez
Member
Registered: 03 May 2009
Posts: 6

Re: How to slice the output of: FSUTIL FSINFO DRIVES

for /f "tokens=2" %%_ in ('fsutil fsinfo drives ^| more') do echo %%_
for /f "tokens=1 skip=2" %%_ in ('fsutil fsinfo drives ^| more') do (
echo %%_
)
wmic logicaldisk get caption | findstr /r /v "^Caption"
for /f "tokens=3 skip=9" %%_ in ('echo list volume ^| diskpart') do (
echo %%_:
)

Offline

#7 13 Dec 2009 20:39

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Been playing around with this for a while using various bits and pieces

it works some of the time but not all of the time

If i use on XP for eg its fine

Using this

set "drlist="
     for /f "tokens=*" %%A in ('fsutil fsinfo drives^|find /V ""') do (
         set "dr=%%A"
         call set "drlist=%%drlist%% %%dr:~-3%%"
     )
     for %%A in (%drlist%) do fsutil fsinfo drivetype %%A

but if i run it on Win 7 it returns

:\ - No such Root Directory

Press any key to continue . . .

I just cant work out whats wrong with it

Heres the output with echo on

H:\Home Backup>set "drlist="

H:\Home Backup>for /F "tokens=*" %A in ('fsutil fsinfo drives|find /V ""') do (
set "dr=%A"
call set "drlist=%drlist% %dr:~-3%"
)

H:\Home Backup>(
set "dr=Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ X:\ Y:\ Z:\ "
call set "drlist=%drlist% %dr:~-3%"
)

H:\Home Backup>for %A in (:\) do fsutil fsinfo drivetype %A

H:\Home Backup>fsutil fsinfo drivetype :\
:\ - No such Root Directory


Press any key to continue . . .

Could i have a lil help please

I may have solved my problem by using this

(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"

which appears to work fine in win 7

creds goto Tima Salmi for the code

Last edited by Chimaera (13 Dec 2009 21:06)

Offline

#8 14 Dec 2009 11:01

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

For what it's worth, I have a script which makes a decent attempt at figuring out drive types (beyond what "fsutil" will show you).  I think I posted it on the forum somewhere already, but here it is again anyway:

@echo off
setlocal enabledelayedexpansion
set drive=
echo:
for /f "usebackq tokens=1*" %%a in (`fsutil fsinfo drives ^| find ":"`) do (
    if /i "%%a" NEQ "Drives:" (
        set "drive=%%a"
    ) ELSE (
        set "drive=%%b"
    )
    set label=
    for /f "usebackq tokens=1* delims=\- " %%A in (`fsutil fsinfo drivetype !drive!`) do (
            for /f "usebackq tokens=5*" %%U in (`vol %%A 2^>nul ^| findstr "^.Volume.in.drive...is" ^| findstr /v "^.Volume.Serial"`) do set label=%%V
        set type=%%B

    )
    set "label=!label!                                "
    set type=!type:~0,-1!
    set drive=!drive:\=!
    for /f "usebackq tokens=2*" %%R in (`subst 2^>nul ^| findstr /i /b "!drive!"`) do set type=SUBST : %%S
    echo:!drive! [!label:~0,32!] !type!
)
echo:
pause

cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#9 14 Dec 2009 15:31

insthink
Member
Registered: 24 Oct 2009
Posts: 51

Re: How to slice the output of: FSUTIL FSINFO DRIVES

I dont know what's going on here, but my output is broken down in lines.

FSUTIL FSINFO DRIVES | find ":"

outputs to

Drives:
C:\
D:\
E:\
F:\
G:\

My CMD version is 5.2.3790   [XP x64]

Last edited by insthink (14 Dec 2009 15:31)

Offline

#10 14 Dec 2009 18:13

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

If you take the "find" off, you might find it appears on one line (on screen).  Well, that's assuming XP x64 behaves like XP x86.


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#11 14 Dec 2009 19:58

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

bluesxman wrote:

For what it's worth, I have a script which makes a decent attempt at figuring out drive types (beyond what "fsutil" will show you).  I think I posted it on the forum somewhere already, but here it is again anyway:

@echo off
setlocal enabledelayedexpansion
set drive=
echo:
for /f "usebackq tokens=1*" %%a in (`fsutil fsinfo drives ^| find ":"`) do (
    if /i "%%a" NEQ "Drives:" (
        set "drive=%%a"
    ) ELSE (
        set "drive=%%b"
    )
    set label=
    for /f "usebackq tokens=1* delims=\- " %%A in (`fsutil fsinfo drivetype !drive!`) do (
            for /f "usebackq tokens=5*" %%U in (`vol %%A 2^>nul ^| findstr "^.Volume.in.drive...is" ^| findstr /v "^.Volume.Serial"`) do set label=%%V
        set type=%%B

    )
    set "label=!label!                                "
    set type=!type:~0,-1!
    set drive=!drive:\=!
    for /f "usebackq tokens=2*" %%R in (`subst 2^>nul ^| findstr /i /b "!drive!"`) do set type=SUBST : %%S
    echo:!drive! [!label:~0,32!] !type!
)
echo:
pause

Yes i tried that one m8 but it gives me this on win 7

C: D: E: F: G:  [                                ] : fsutil
fsinfo drivetype C

Press any key to continue . . .

Is that how its supposed to output?, or am i doing something wrong

Offline

#12 14 Dec 2009 20:56

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

No, that's certainly not how it's supposed to look!  If you're running the code as-is, it should just work.

Knowing Microsoft, I expect they tweaked something in the format of the command output and that's what's throwing it off.  They have a habit of moving things around just for the sake of it in the GUI, so probably do the same for the command line stuff.  It's probably a trivial one to fix, but I'm afraid I've not got a copy of Win7 to test against.


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#13 14 Dec 2009 21:17

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Heres the output if that helps

H:\TS Backup Files>setlocal enabledelayedexpansion

H:\TS Backup Files>set drive=

H:\TS Backup Files>echo:


H:\TS Backup Files>for /F "usebackq tokens=1*" %a in (`fsutil fsinfo drives | fi
nd ":"`) do (
if /I "%a" NEQ "Drives:" (set "drive=%a" )  ELSE (set "drive=%b" )
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype !drive!`
) do (
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
set drive=!drive:\=!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "!drive!"`) do
set type=SUBST : %S
echo:!drive! [!label:~0,32!] !type!
)

H:\TS Backup Files>(
if /I "Drives:" NEQ "Drives:" (set "drive=Drives:" )  ELSE (set "drive=C:\ D:\ E
:\ F:\ G:\ H:\ I:\ J:\ K:\ X:\ Y:\ Z:\ " )
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype !drive!`
) do (
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
set drive=!drive:\=!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "!drive!"`) do
set type=SUBST : %S
echo:!drive! [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol Usage 2>nul | findstr "^.Volume.in.drive
...is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=: fsutil fsinfo drivetype <volume pathname>
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol Eg 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=: fsutil fsinfo drivetype C:
)
C: D: E: F: G: H: I: J: K: X: Y: Z:  [                                ] : fsutil
fsinfo drivetype C

H:\TS Backup Files>echo:


H:\TS Backup Files>pause
Press any key to continue . . .

Offline

#14 15 Dec 2009 12:21

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Ah OK, I think I see what's going on there.

Hopefully this version should be a bit more tolerant -- but see previous disclaimer about the lack of a Win7 install to test against (the only thing I say for certain is that the changes I've made don't break it on my WinXP).

@echo off
setlocal enabledelayedexpansion
set drive=
echo:
for /f "usebackq tokens=1*" %%a in (`fsutil fsinfo drives ^| find ":"`) do (
    if /i "%%a" NEQ "Drives:" (
        set "drive=%%a"
    ) ELSE (
        set "drive=%%b"
    )
    set drive=!drive:\=!
    for %%D in (!drive!) do (
        set label=
        for /f "usebackq tokens=1* delims=\- " %%A in (`fsutil fsinfo drivetype %%D`) do (
            for /f "usebackq tokens=5*" %%U in (`vol %%A 2^>nul ^| findstr "^.Volume.in.drive...is" ^| findstr /v "^.Volume.Serial"`) do set label=%%V
            set type=%%B
        )
        set "label=!label!                                "
        set type=!type:~0,-1!
        for /f "usebackq tokens=2*" %%R in (`subst 2^>nul ^| findstr /i /b "%%D"`) do set type=SUBST : %%S
        echo:%%D [!label:~0,32!] !type!
    )
)
echo:
pause

cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#15 15 Dec 2009 17:37

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Now we are cooking on gas

Output as follows

C: [Main Drive                         ] Fixed Driv
D: [Main Setup                        ] Fixed Driv
E: [System Reserved               ] Fixed Driv
F: [Gaming Drive                      ] Fixed Driv
G: [                                          ] CD-ROM Driv
H: [USB_TOOLS                       ] Removable Driv
I: [Gaming Setup                     ] Fixed Driv
J: [                                           ] CD-ROM Driv
K: [                                          ] CD-ROM Driv
X: [Storage_Music                   ] Fixed Driv
Y: [Storage_Apps                    ] Fixed Driv
Z: [Storage_Games                 ] Fixed Driv

Press any key to continue . . .

Echo On output for checking

(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "%D"`) do set t
ype=SUBST : %S
echo:%D [!label:~0,32!] !type!
)
)

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype C:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "C:"`) do set t
ype=SUBST : %S
echo:C: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol C: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Main Drive
C: [Main Drive                      ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype D:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "D:"`) do set t
ype=SUBST : %S
echo:D: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol D: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Main Setup
D: [Main Setup                      ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype E:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "E:"`) do set t
ype=SUBST : %S
echo:E: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol E: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=System Reserved
E: [System Reserved                 ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype F:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "F:"`) do set t
ype=SUBST : %S
echo:F: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol F: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Gaming Drive
F: [Gaming Drive                    ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype G:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "G:"`) do set t
ype=SUBST : %S
echo:G: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol G: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=CD-ROM Drive
)
G: [                                ] CD-ROM Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype H:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "H:"`) do set t
ype=SUBST : %S
echo:H: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol H: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Removable Drive
)

H:\TS Backup Files>set label=USB_TOOLS
H: [USB_TOOLS                       ] Removable Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype I:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "I:"`) do set t
ype=SUBST : %S
echo:I: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol I: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Gaming Setup
I: [Gaming Setup                    ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype J:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "J:"`) do set t
ype=SUBST : %S
echo:J: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol J: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=CD-ROM Drive
)
J: [                                ] CD-ROM Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype K:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "K:"`) do set t
ype=SUBST : %S
echo:K: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol K: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=CD-ROM Drive
)
K: [                                ] CD-ROM Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype X:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "X:"`) do set t
ype=SUBST : %S
echo:X: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol X: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Storage_Music
X: [Storage_Music                   ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype Y:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "Y:"`) do set t
ype=SUBST : %S
echo:Y: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol Y: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Storage_Apps
Y: [Storage_Apps                    ] Fixed Driv

H:\TS Backup Files>(
set label=
for /F "usebackq tokens=1* delims=\- " %A in (`fsutil fsinfo drivetype Z:`) do
(
for /F "usebackq tokens=5*" %U in (`vol %A 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=%B
)
set "label=!label!                                "
set type=!type:~0,-1!
for /F "usebackq tokens=2*" %R in (`subst 2>nul | findstr /i /b "Z:"`) do set t
ype=SUBST : %S
echo:Z: [!label:~0,32!] !type!
)

H:\TS Backup Files>(
for /F "usebackq tokens=5*" %U in (`vol Z: 2>nul | findstr "^.Volume.in.drive...
is" | findstr /v "^.Volume.Serial"`) do set label=%V
set type=Fixed Drive
)

H:\TS Backup Files>set label=Storage_Games
Z: [Storage_Games                   ] Fixed Driv

H:\TS Backup Files>echo:


H:\TS Backup Files>pause
Press any key to continue . . .

Thx for your time Bluesxman

One small thought on this bit

C: [Main Drive                         ] Fixed Driv
D: [Main Setup                        ] Fixed Driv
E: [System Reserved               ] Fixed Driv
F: [Gaming Drive                      ] Fixed Driv

Is it possible to get it so the word driv becomes drive

EDIT
Think ive found the bit
set "label=!label!                                "
        set type=!type:~0,-1!

The minus 1 seems to be the culprit
Ive changed mine to 16 and it seems to be ok, but not sure if this has repurcussions on any other bits

Last edited by Chimaera (15 Dec 2009 18:06)

Offline

#16 16 Dec 2009 00:48

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

I don't recall specifically what the -1 was for, but it was probably to dodge a troublesome character that the WinXP version of "fsutil" tacked on the end of the line.

You could probably just remove the "set type=!type:~0,-1!" line altogether.


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#17 10 Jan 2010 13:01

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Just curious about something bluesxman

is there a similar thing to this to show network drives as well?
ive been messing with a few of the net commands and cant seem to get a simple thing that outputs in the same way

thx

Offline

#18 10 Jan 2010 23:39

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

If the "net use" command doesn't show it the way you want, you can always try to write a script around it.


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#19 11 Jan 2010 15:39

Drewfus
Member
From: Australia
Registered: 11 Jan 2010
Posts: 44

Re: How to slice the output of: FSUTIL FSINFO DRIVES

My first post here.
Hello.

<code>
@echo off
setlocal enabledelayedexpansion
for /F "tokens=1,*" %%A in ('fsutil fsinfo drives') do set drives=%%B
:loop
if defined drives for /F %%A in ('echo %drives%') do call :drives %%A
goto :eof

:drives
echo %1
set drives=!drives:%1 =!
goto :loop
</code>

Offline

#20 11 Jan 2010 21:07

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Not quite sure where ur heading there Drewfus it just flashes and exits

Thx anyway

Offline

#21 12 Jan 2010 00:08

Drewfus
Member
From: Australia
Registered: 11 Jan 2010
Posts: 44

Re: How to slice the output of: FSUTIL FSINFO DRIVES

I get;

C:\
D:\
E:\

Perhaps try it with echoing on.

Offline

#22 12 Jan 2010 09:38

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: How to slice the output of: FSUTIL FSINFO DRIVES

I did m8 but bear in mind im running windows 7

this is the current one we are working on courtesy of bluesxman which gives more detail

@echo off
setlocal enabledelayedexpansion
set drive=
echo:
for /f "usebackq tokens=1*" %%a in (`fsutil fsinfo drives ^| find ":"`) do (
    if /i "%%a" NEQ "Drives:" (
        set "drive=%%a"
    ) ELSE (
        set "drive=%%b"
    )
    set drive=!drive:\=!
    for %%D in (!drive!) do (
        set label=
        for /f "usebackq tokens=1* delims=\- " %%A in (`fsutil fsinfo drivetype %%D`) do (
            for /f "usebackq tokens=5*" %%U in (`vol %%A 2^>nul ^| findstr "^.Volume.in.drive...is" ^| findstr /v "^.Volume.Serial"`) do set label=%%V
            set type=%%B
        )
        set "label=!label!                                "
        set type=!type:~0,-1!
        for /f "usebackq tokens=2*" %%R in (`subst 2^>nul ^| findstr /i /b "%%D"`) do set type=SUBST : %%S
        echo:%%D [!label:~0,32!] !type!
    )
)
echo:
pause

Last edited by Chimaera (12 Jan 2010 09:39)

Offline

#23 12 Jan 2010 12:42

Drewfus
Member
From: Australia
Registered: 11 Jan 2010
Posts: 44

Re: How to slice the output of: FSUTIL FSINFO DRIVES

This is a bit of a hack but i think it's what you want.
Requires dosdev.exe in %CD% or path.

@echo off
setlocal enabledelayedexpansion
dosdev > dosdev.txt
for /F "tokens=*" %%A in (dosdev.txt) do call :vols %%A
goto :eof

:vols
for /F "tokens=1,2,*" %%A in ('echo %*') do (
set DL=%%A
set DT=%%C
)
for /F "tokens=6,7" %%A in ('vol %DL% ^| find "Volume in drive"') do (
set label=%%A %%B
)
set LL=0
if "%label%" equ "no label." (set label=) else (
call :LL
)
if %LL%==0 (set gap=0) else set /A gap=%LL%+1
set DT=           %DT%
set DT=!DT:~%gap%!
echo %DL% %label% %DT%
goto :eof

:LL
setlocal
set var=%label%
:loop
set var=%var:~1%
if not defined var (
endlocal & set LL=%LL% & goto :eof
)
set /A LL+=1
goto :loop

Offline

#24 24 Feb 2011 11:34

marianrobert79
Member
Registered: 24 Feb 2011
Posts: 1

Re: How to slice the output of: FSUTIL FSINFO DRIVES

The correct list of drives is fastest shown with command below in XP:

for /f "delims=: usebackq tokens=*" %f in (`fsutil fsinfo drives^|find ":"`) do @echo %~df

For me it correctly returns:
C:
D:
E:
F:
G:
H:
M:
N:
O:
Y:
Z:

Offline

#25 25 Feb 2011 18:35

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 931

Re: How to slice the output of: FSUTIL FSINFO DRIVES

That doesn't work correctly.  If I'm on my C: drive, all looks well.  If I change to another drive I get this output:

D:\>for /f "usebackq tokens=*" %f in (`fsutil fsinfo drives^|find ":"`) do @echo %~df
D:
D:
E:
F:
G:
H:
I:
K:
X:
Z:

Note that the first drive letter shown is that of my current drive context (if I change to G:, I see "G: D: E:...").

Last edited by bluesxman (25 Feb 2011 18:37)


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#26 28 Feb 2011 12:44

allal
Member
Registered: 10 Jan 2011
Posts: 48

Re: How to slice the output of: FSUTIL FSINFO DRIVES

oops i m in the second page

Last edited by allal (28 Feb 2011 14:26)

Offline

#27 25 Nov 2011 10:29

hasty
Member
Registered: 25 Nov 2011
Posts: 1

Re: How to slice the output of: FSUTIL FSINFO DRIVES

Hi, I don't know how to get only fixed drive letters as variable in a script. My idea is to make smart batch file to copy files only to fixed HDD.  Someone can help me ?

1. C:\ - Fixed Drive
2. D:\ - Fixed Drive
...
n. .... - Fixed Drive

Pls. select drive Nr. :

I use this script to get fixed drive letters

@echo off
setlocal
	set "list="
	for /f "tokens=*" %%a in ('^
	fsutil fsinfo drives^|
	find /V ""'
) do (
	set "dv=%%a"
	call set "list=%%list%% %%dv:~-3%%"
)
	for %%a in (%list%) do (
	fsutil fsinfo drivetype %%a|findstr /c:"Fixed Drive"
)

pause
exit

Offline

#28 25 Nov 2011 14:33

RG
Member
From: Ohio
Registered: 18 Feb 2010
Posts: 318

Re: How to slice the output of: FSUTIL FSINFO DRIVES

I can confirm what some of you have suspected... FSUTIL output definitely varies by OS!.  Thanks Microsoft!
I don't have multiple machines to test with at the moment, but comments in one of my files have this note about Vista (and presumably newer OS's)
"FSUTIL FSINFO DRIVES on Vista puts nulls between drives instead of spaces!"
Some of the the wierdness in FSUTIL's output (referred to by bluesxman) is vertical tabs and single linefeeds (no CR).
I think there are also trailing CR's.... maybe only on some OS's... which would explain one of the posts farther back where a trailing character was being removed.
The moral of the story here is....whatever you come up with using FSUTIL needs to be tested across all OS's that you might encounter!
There are a lot of posts here so I won't test each suggestion, but if you want to repost the current implementation and I can test on whatever OS you don't have available.


CMD and InstallShield

Offline

Board footer

Powered by FluxBB