Getting volume information

  • Thread starter Thread starter herc
  • Start date Start date
H

herc

My objective is to get the "label" information for the different
volumes that are mounted. I want to display the same information as
Windows Explorer. I wrote this test code with gets me the drive
letter, but the label is always blank. Any thoughts?

DriveInfo[] drives = DriveInfo.GetDrives();

foreach (DriveInfo di in drives)
{
Console.WriteLine("----------------------");
if (di.IsReady)
{
Console.WriteLine("label: {0}", di.VolumeLabel);
Console.WriteLine("Format: {0}", di.DriveFormat);
Console.WriteLine("Name: {0}", di.Name);
}
Console.WriteLine("Root Directory: {0}", di.RootDirectory);
Console.WriteLine("Type: {0}", di.DriveType);
Console.WriteLine("Is Ready: {0}", di.IsReady);
}
 
Hi,

Your code should work fine, did you check in your explorer and make sure
you have a label?
 
Gandalf,

This is interesting, here is what I get when I run the program, or at
least part of it:


----------------------
Root Directory: D:\
Type: CDRom
Is Ready: False
----------------------
Root Directory: E:\
Type: CDRom
Is Ready: False
----------------------
Root Directory: F:\
Type: CDRom
Is Ready: False
----------------------
label:
Format: NTFS
Name: G:\
Root Directory: G:\
Type: Network
Is Ready: True
----------------------

When I look at Windows Explorer (running XPSP2), things are displayed
this way:

DVD Drive (D:)
DVD-RW Drive (E:)
DVD Drive (F:)
cartoof on '172.16.52.2' (G:)

How is it getting that the CDRom's are really DVD's and DVD-RW and how
is it getting the actual share name of the network drive mounted to G:?
I am trying to develop to the lowest common factor, thus more
information is ideal;)
 
An extra note:

My real objective is to know the difference in removable drives. I
don't want to mess with the floppies, but I do need to know which
drives are external hard drives and which are card readers.
 
When I say Card Reader, I am refering to all the flash cards that are
out there today for digital cameras and MP3 players.
I just had another thought (doesn't happen often I have to brag when it does :)

Nice to know that I am not the only one!
Do you you any media actually IN the drives when you run your code? I think
my DVD/CD drive just shows as yours does when it is empty, but shows a "Audio
CD" when loaded with one.

That would only leave your network drive without a name...possible it really
doesn't have one?

Gandalf,

What I am looking for is as much detailed info about the hardware as is
avalable. I would like to have more then just the label of the volume.
But to answer your question, I do not have media in any of the optical
drives which is why I not really expecting a label there. BUT Windows
Explorer knows that one is a DVD-RW and the other is a DVD, not simply
a CD Rom. The question is: how?

With respect to the network labels, it does seem a bit strange that
yours have labels and mine don't. I wonder what consititudes a network
mappings drive label.

I did see some WinSDK calls relating to volume information, but I don't
see any in the .Net Framework. I am wondering if anyone know of any
calls above and beyond my sample code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top