Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you locate the 1st available removable drive in code?

Status
Not open for further replies.

emaduddeen

Programmer
Mar 22, 2007
184
US
Hi Everyone,

I would like to write some code that will locate the 1st. available removable disk drive such as a thumb drive and store that drive letter into a variable.

Can you tell me how do this.

Thanks.

Truly,
Emad
 
I never tried this, and can't test it from here as I don't have VB installed on this computer, but off the top of my head, is there not a system.io.driveinfo that might have the information you're looking for? Sorry I can't be more specific, but someone else might have more on that...



Cheers,

Realm174
 
Hi realm174,

I was able to find a solution:

Code:
    Private Sub FindThumbDrive()
        ' Find the highest drive letter of a thumb drive inserted into the computer.
        '---------------------------------------------------------------------------
        For Each objDrive As DriveInfo In DriveInfo.GetDrives
            If objDrive.DriveType = DriveType.Removable Then
                strDestinationDrive = objDrive.Name
            End If
        Next

        If strDestinationDrive = Nothing Then
            MessageBox.Show("I can't do any backups because there is no " & _
                                            "thumb drive found on your computer." & _
                                            vbCrLf & vbCrLf & _
                                            "Please insert one and try again.", "Important", _
                                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub

Truly,
Emad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top