Get Available Drive Letter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Marden

    Get Available Drive Letter

    I am making a program for work that Maps to different hmi's (human - machine
    interface) computers and makes a backup of the files we currently use in
    them. It then unmaps the drives. I have a function that gets the first
    available drive starting with Z and working backwords from thier. This
    function works well in vb2005 but our work pc's only have .net framework
    1.1.4322 so I need to change it to work with vb2003. Please help me with my
    problem.

    The following is the code I am currently using for this.

    Public Function GetDriveLetter( )
    Dim intAlpha As Integer
    Dim strAlpha As String
    Dim boolDriveExists As Boolean
    Dim myDrives As DriveInfo() = DriveInfo.GetDr ives()
    strAlpha = "ZYXWVUTSRQPONM LKJIHGFEBDA"
    For intAlpha = 1 To Len(strAlpha)
    boolDriveExists = False
    GetDriveLetter = Mid(strAlpha, intAlpha, 1) & ":"
    For Each d As DriveInfo In myDrives
    If d.Name = CStr(GetDriveLe tter & "\") Then
    boolDriveExists = True
    End If
    Next
    If boolDriveExists = False Then
    Exit Function
    End If
    Next
    End Function

    Any help would be appreciated,
    Dave Marden


  • Cor Ligthert[MVP]

    #2
    Re: Get Available Drive Letter

    Dave,



    Cor

    "Dave Marden" <newsgroup@mard enfamily.comsch reef in bericht
    news:Oh$WQVk7HH A.3528@TK2MSFTN GP04.phx.gbl...
    >I am making a program for work that Maps to different hmi's (human -
    >machine interface) computers and makes a backup of the files we currently
    >use in them. It then unmaps the drives. I have a function that gets the
    >first available drive starting with Z and working backwords from thier.
    >This function works well in vb2005 but our work pc's only have .net
    >framework 1.1.4322 so I need to change it to work with vb2003. Please help
    >me with my problem.
    >
    The following is the code I am currently using for this.
    >
    Public Function GetDriveLetter( )
    Dim intAlpha As Integer
    Dim strAlpha As String
    Dim boolDriveExists As Boolean
    Dim myDrives As DriveInfo() = DriveInfo.GetDr ives()
    strAlpha = "ZYXWVUTSRQPONM LKJIHGFEBDA"
    For intAlpha = 1 To Len(strAlpha)
    boolDriveExists = False
    GetDriveLetter = Mid(strAlpha, intAlpha, 1) & ":"
    For Each d As DriveInfo In myDrives
    If d.Name = CStr(GetDriveLe tter & "\") Then
    boolDriveExists = True
    End If
    Next
    If boolDriveExists = False Then
    Exit Function
    End If
    Next
    End Function
    >
    Any help would be appreciated,
    Dave Marden
    >

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Get Available Drive Letter

      Dave,



      Cor

      "Dave Marden" <newsgroup@mard enfamily.comsch reef in bericht
      news:Oh$WQVk7HH A.3528@TK2MSFTN GP04.phx.gbl...
      >I am making a program for work that Maps to different hmi's (human -
      >machine interface) computers and makes a backup of the files we currently
      >use in them. It then unmaps the drives. I have a function that gets the
      >first available drive starting with Z and working backwords from thier.
      >This function works well in vb2005 but our work pc's only have .net
      >framework 1.1.4322 so I need to change it to work with vb2003. Please help
      >me with my problem.
      >
      The following is the code I am currently using for this.
      >
      Public Function GetDriveLetter( )
      Dim intAlpha As Integer
      Dim strAlpha As String
      Dim boolDriveExists As Boolean
      Dim myDrives As DriveInfo() = DriveInfo.GetDr ives()
      strAlpha = "ZYXWVUTSRQPONM LKJIHGFEBDA"
      For intAlpha = 1 To Len(strAlpha)
      boolDriveExists = False
      GetDriveLetter = Mid(strAlpha, intAlpha, 1) & ":"
      For Each d As DriveInfo In myDrives
      If d.Name = CStr(GetDriveLe tter & "\") Then
      boolDriveExists = True
      End If
      Next
      If boolDriveExists = False Then
      Exit Function
      End If
      Next
      End Function
      >
      Any help would be appreciated,
      Dave Marden
      >

      Comment

      Working...