×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Get USB drive's letter

Get USB drive's letter

Get USB drive's letter

(OP)
This app reads from and backs up data files to a USB thumb drive.
The problem is that the USB drive is used with several machines and its allocated drive letter varies.

How can I determine the USB's current drive letter?
(VFP7 and XP)  

RE: Get USB drive's letter

This might be helpful.  

From MSDN(http://msdn.microsoft.com/en-us/library/ys4ctaz0%28VS.85%29.aspx)



Function ShowDriveType(drvpath)
   Dim fso, d, t
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set d = fso.GetDrive(drvpath)
   Select Case d.DriveType
      Case 0: t = "Unknown"
      Case 1: t = "Removable"
      Case 2: t = "Fixed"
      Case 3: t = "Network"
      Case 4: t = "CD-ROM"
      Case 5: t = "RAM Disk"
   End Select
   ShowDriveType = "Drive " & d.DriveLetter & ": - " & t
End Function
 

RE: Get USB drive's letter

Dores the thunmb drive not have a volume name? And if not, can one be set?

If the answer to either of the above is 'yes', then you can use the FSO to iterate through the attached drives interrogating the VolumeName propery until you find the drive you want. Something like the following:

CODE

    Dim objDrive As Object
    
    With CreateObject("Scripting.FileSystemObject")
    For Each objDrive In .Drives
        If objDrive.IsReady Then ' skip unready drives such as empty CD and DVD drives
            If objDrive.VolumeName = "Example" Then
                MsgBox "Drive is " & objDrive.Path
                Exit For
            End If
        End If
    Next
    End With

RE: Get USB drive's letter

(OP)
thanks - looks as though drivetype() will do the job

RE: Get USB drive's letter

This sort of thing seems clever... until you run into cases where more than one removable drive is encountered.

People do use ReadyBoost for one thing, and some still have floppy drives.

RE: Get USB drive's letter

(OP)
Thanks; this should be OK though.It's for a dedicated netbook, running a VFP app and (for security reasons) using only data kept on a single protected USB stick.   

RE: Get USB drive's letter

>the USB drive is used with several machines and its allocated drive letter varies
>It's for a dedicated netbook

How do theses two statements tally?

RE: Get USB drive's letter

(OP)
How do theses two statements tally?

The netbook is used by an on-call technician to run a specific VFP app (tissue typing for heart/lung transplants) when needed out of lab hours.
The data files used are on a security locked USB key.
Each evening the USB key is updated from the server via one of the networked day-time  PCs.  Changed files are transferred back to the lab network next morning via any free PC.

And drivetype() does do the job thanks

  

RE: Get USB drive's letter

I'm sure it does. But either

a) it is for a dedicated machine, in which case drive letters won't change, so drivetype() will work without issue - but is not actually needed

b) it is for multiple machines, in which case drive letters change and may change because they have different numbers of removeable drives in which case drivetype() won't work 100% of the time (dilettante's point)

All we are saying is be careful.  

RE: Get USB drive's letter

(OP)
>> All we are saying is be careful.<<

Thanks - it'll be error trapped.  
(I know xp can do odd things with external drive letter allocation)

 

RE: Get USB drive's letter

Yes, what I was suggesting comes down to supplying a DriveListBox to let the user choose the correct drive.  You could make your own selecting only removable drives and displaying the volume name in order to help the user make the correct selection.

RE: Get USB drive's letter

(OP)
thanks everyone - I don't know how this got into the VB forum .It's for a VFox application and I thought I was in that forum when I sent the original message.
  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close