![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
Mixing GetLogicalDrive and DriveInfo
Hey yall. I got my program to get all dirves on the system. But now I want to make it show the VolumeLabel of the drive. How can I do that I kno you have to use DriveInfo and then drive.volumelabel. But I nned to still use GetLogicalDrives and still also use driveinfoto get volumelabel unless theres another way. YThanks
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Hey, the following code is in C#, but it is very similar to VB.NET. Its the same classes and stuff, just some of the vars of lines may need to be coded a little differently. As I said, the classes are the same.
//You shouldnt even need these first 2 lines
string[] drives; //String array holds drive letters
Drives = Directory.GetLogicalDrives();
//Display first 2 drive letters
//MessageBox.Show(drives[0].ToString()); //Should Probably return C:
//MessageBox.Show(drives[1].ToString()); //Should Probably return D:
//Determines whether specified Drive Exists
DriveInfo di = new DriveInfo("C:");
//Get volume label
MessageBox.Show(di.VolumeLabel.ToString());
//MessageBox.Show(di.DriveType.ToString());Anyways, that code works for C#, try and edit it a bit to fit vb.net, and lemme know if it works. Hope it helps. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Yeah but each drive letter on systems can be different. Will that code still work?
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Yup.
//You shouldnt even need these first 2 lines
string[] drives; //String array holds drive letters
Drives = Directory.GetLogicalDrives();
//Display first 2 drive letters
//MessageBox.Show(drives[0].ToString()); //Should Probably return C:
//MessageBox.Show(drives[1].ToString()); //Should Probably return D:That code will give you a list of the drive letters. Starting at 0 in the array, it will go until there are no more drives. Then in the line: DriveInfo di = new DriveInfo("C:");Just replace "C:" with the drives[0].ToString() You can change it to another variable, or throw it in a loop or something if you want all teh drives. That will work for you though. |
|
|
|
|
|
#5 |
|
Professional Programmer
|
Public Sub GetDrives()
Dim drives As String() = Directory.GetLogicalDrives
For Each drive As String In drives
Dim di As DriveInfo = New DriveInfo(drive)
Dim newlst1 As ListViewItem
newlst1 = lstdrives.Items.Add(0)
Try
newlst1.Text = (drive + " (" + di.VolumeLabel + ")")
Catch ex As Exception
newlst1.Text = (drive & "")
End Try
Next
End SubThis is what I have so far what it does is put drivename:/() in the listviewbox. I dont know what to do.
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. |
|
|
|
|
|
#6 | |
|
Expert Programmer
|
Quote:
Is that right? Sorry, havent tested the code you have there. What other result do you want. Judging by the code, look slike the volume label should show up between the brackets. Do you have labels on the drives? |
|
|
|
|
|
|
#7 |
|
Professional Programmer
|
Well, I feel dumb. I was thinking Local Disk was a Volume Label. It's not. Thanks for teh help yall provided even though it was me all along.
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|