Solved

batch script to determine hard disk

Posted on 2007-12-03
3
744 Views
Last Modified: 2010-04-21
Hello Experts,

I'm writting a script to determine the fixed drives in a computer and put the output in a text file. There is a simple sample of my test but didn't work.

fsutil fsinfo drives|findstr /I /V "Units: " > c:\Units.txt
for /F "eol=; tokens=* delims= " %%i in (Units.txt) do fsutil fsinfo drivetype %%i|findstr /I /X "%%i- Fixed Drive" > HDisks.txt

Any help?? Thanks!
0
Comment
Question by:apendes
3 Comments
 
LVL 16

Expert Comment

by:gurutc
Comment Utility
Hi,

Thinking about this question, I come up with a couple of conclusions, possibly wrong.

First, you probably won't have more than 4 physical drives to check, so you can limit your search to drives c: through f: or so.

Second, you can make sure you don't have a ton more local drives by checking the lastdrive environment variable.

Third, other options may be available, depending on whether this is true DOS or a command shell.

Fourth, brute force, ie change to each drive letter and check for an error-level condition.

Good Luck,

- gurutc
0
 
LVL 82

Accepted Solution

by:
oBdA earned 250 total points
Comment Utility
The output of "fsutil fsinfo drives" looks pretty neat, but is in fact everything else, because for whatever reason, it prints Chr(0) between the drives listed, which confuses "for /f".
Try the script below, which simply checks all drive letters if they're fixed.
@echo off

setlocal

set HDFile=HDisks.txt

if exist "%HDFile%" del "%HDFile%"

set DriveList=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:

for %%a in (%DriveList%) do (

  echo Checking %%a ...

  fsutil fsinfo drivetype %%a | find /i "Fixed Drive" >NUL

  if not errorlevel 1 (

    >>"%HDFile%" echo %%a

    echo %%a

  )

)

Open in new window

0
 

Author Closing Comment

by:apendes
Comment Utility
Its a very clear method to acomplish my request.
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now