Solved

batch script to determine hard disk

Posted on 2007-12-03
3
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:gurutc
ID: 20394985
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 84

Accepted Solution

by:
oBdA earned 250 total points
ID: 20395116
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
ID: 31412301
Its a very clear method to acomplish my request.
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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