Evolution of a solution

The other day, someone posted a message at work asking for a way to find out the drive letter for partition 1 on the first disk.

The first response offered this:

C:>echo list volume | diskpart
Microsoft DiskPart version 5.1.3565

Copyright (C) 1999-2003 Microsoft Corporation.

On computer: SINISTAR

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     F                       DVD-ROM         0 B
  Volume 1     C   BOOTDRIVE    FAT32  Partition      9 GB  Healthy    System
  Volume 2     D   Application  NTFS   Partition     15 GB  Healthy    Pagefile
  Volume 3     E   SharedAndUn  NTFS   Partition     10 GB  Healthy



The original poster then asked if anyone already had a script to parse the output of diskpart. I helpfully offered this:

@for /f "tokens=3" %%x in ('echo list volume ^| diskpart ^| findstr /c:"Volume %1"') do @echo %%x

"How clever of me," thought I. "Simply pass in a volume number and it neatly spits out the drive letter." I was all proud of myself until someone pointed out that we already had a perfectly good .exe that did the same thing.

The moral? It's all fun and games 'til you find out you just reinvented the wheel...

Comments (2)
  1. Ron Krauter says:

    ..and what is the name of that exe? thanks.

  2. myocom says:

    It’s something that someone wrote internally. I can’t find any reference to any other .exe by that name (getdriveletter.exe), but I’m sure a thin wrapper around a Win32 API call.

    Me? For my purposes I still stick with the one-line script.

Comments are closed.

Skip to main content