How To Determine FlashDrive Letter

lhooker

Registered User.
Local time
Today, 13:44
Joined
Dec 30, 2005
Messages
423
Is there anyway to determine the drive letter of a flashdrive inserted into a PC ? I have a backup routine that backs up a MS Access database to a flashdrive. I need to determine the flashdrive letter.
 
JDraw,

Thanks ! ! ! . . . I took a look at the solution. Is there anyway to check if a drive letter exists ? The drive letters that are used are "E" and "F". If I knew which drive letter existed, then I could point the backup routine to the existing drive letter.
 
I haven't used the material at the link. Did you look at his tutorial and try it. I don't think you have to have contiguous letters (just guessing based on his letters).
Try his technique, then test the result; then you will know exactly whether it meets your needs or not.
Good luck. Let us know what your tests show. It could help others.
 
JDraw,

I'll try and report back. I was hoping to find a solution that would check if a drive letter exists, then point the backup routine to the existing PC flashdrive drive letter. The drive letters that are used by the PC flashdrive(s) are "E" and "F".
 
The link provided shows how to manually assign another drive letter to a storage device.

I can't test here but try
? dir("F:\")
and
? dir("E:\")
 
Is there anyway to determine the drive letter of a flashdrive inserted into a PC ? I have a backup routine that backs up a MS Access database to a flashdrive. I need to determine the flashdrive letter.

Here is a stub of a routine which I am using to seek a license file on a flash drive:

Code:
Public Function GetLicDrive() As String
     '
    Dim FSO As Object, Drive As Object, Info As String, DrL As String
    Dim DrLetters As String, d As Integer, Released As Boolean
     '
    Set FSO = CreateObject("Scripting.FileSystemObject")
 
     '
    DrLetters = "EFGHIJKLMN"
    GetLicDrive = "Not Found"
    On Error Resume Next
    Released = False
    Do Until Released
      For d = 1 To 10
        DrL = MID(DrLetters, d, 1) & ":"
        Set Drive = FSO.GetDrive(DrL)
        If Drive.DriveType = 1 Then ' = "Removable"
          If Drive.IsReady Then
            If Drive.VolumeName = "MyName"  '<==establish ID of drive 
              GetLicDrive = DrL
              Released = True
              Exit For
            End If
          End If
        End If
      Next d
      If GetLicDrive = "Not Found" Then
        d = MsgBox("Insert Jump Drive in a USB Port and Press Ok !", vbOKCancel + vbExclamation)
        If d = vbCancel Then Released = True
      End If
    Loop
End Function

Hopefully, the routine is easy to adapt for your purposes.

Best,
Jiri
 
Last edited:
lhooker,

I just followed the instructions in the link I posted earlier. I set up my flash stick(kingston Data Traveller) as T: using the method in the link. It worked fine. I saved the drive letter change , then closed the Control Panel etc. I did a safely remove flash stick, and then reinserted the flash stick into a different USB port. It shows up as T:. I was trying to get my flash drive to have a constant/static Drive letter, and this seems to do it.

If your flash drive has a specific DriveName, then I think the code Jiri proposed would go thru a list of drive letters and look for your driveName.

I'm running Windows 8.1
 
Last edited:
Technically, drive letters A-Z always exist but may be de-referenced (i.e. not mapped; not pointing to anything). The file system object lets you look at the current directory and you can change directories. If you declared a trap handler in front of code to do fso.ChDir("driveletter:/") and didn't get an error, you could then try do fso.GetAttr("driveletter:/") to see if it comes back as a directory (vbDirectory). If the drive isn't mapped, you would take the trap or at least not find the root directory of that drive letter.
 
Thanks to everyone who responded ! ! ! I already applied Jraw's solution and it worked fine.
 

Users who are viewing this thread

Back
Top Bottom