Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2006, 1:52 PM   #1
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
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.
bigguy is offline   Reply With Quote
Old Jul 4th, 2006, 8:45 PM   #2
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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.
Booooze is offline   Reply With Quote
Old Jul 5th, 2006, 2:44 AM   #3
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
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.
bigguy is offline   Reply With Quote
Old Jul 5th, 2006, 11:22 AM   #4
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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.
Booooze is offline   Reply With Quote
Old Jul 5th, 2006, 4:09 PM   #5
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
 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 Sub


This 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.
bigguy is offline   Reply With Quote
Old Jul 6th, 2006, 12:11 AM   #6
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Quote:
This is what I have so far what it does is put drivename:/() in the listviewbox. I dont know what to do.
As in --> C:/()

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?
Booooze is offline   Reply With Quote
Old Jul 6th, 2006, 2:06 AM   #7
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
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.
bigguy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC