hello guys..
all i want is to open the path of my usb flash disk when the user click the command button..
but i cant specified the correct drive letter of my flash disk..
pls help me..
Printable View
hello guys..
all i want is to open the path of my usb flash disk when the user click the command button..
but i cant specified the correct drive letter of my flash disk..
pls help me..
Welcome to the forums! :wave:
You may want to have a look at this. You could modify it to suit your needs, that is to enumerate just the removable drives for you to determine your USB drive.
Or you could probably just detect if a USB drive is being inserted and determine its drive letter?
i have d same problem..
thanks for the links..
This will find your drive letter and open a file:
Notes:Code:Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Command1_Click()
Dim UsbDrive As String
Dim fnumber As Integer
Dim myfile As String
Dim Mydata As String
fnumber = FreeFile
UsbDrive = GetUsbDriveLetter
myfile = UsbDrive & "\temp.txt"
Open myfile For Input As #fnumber
Line Input #fnumber, Mydata
MsgBox Mydata
Close #fnumber
End Sub
Public Function GetUsbDriveLetter() As String
Dim I As Integer
For I = 65 To 90
If DriveType(Chr$(I)) = "removeable" Then
If Chr$(I) <> "A" Then 'A shows as removal
GetUsbDriveLetter = Chr$(I) & ":\"
End If
End If
Next I
End Function
Private Function DriveType(sDrive As String) As String
Dim sDriveName As String
Const DRIVE_TYPE_UNDTERMINED = 0
Const DRIVE_ROOT_NOT_EXIST = 1
Const DRIVE_REMOVABLE = 2
Const DRIVE_FIXED = 3
Const DRIVE_REMOTE = 4
Const DRIVE_CDROM = 5
Const DRIVE_RAMDISK = 6
sDriveName = GetDriveType(sDrive & ":\")
Select Case sDriveName
Case DRIVE_TYPE_UNDTERMINED
DriveType = "unknown"
Case DRIVE_ROOT_NOT_EXIST
DriveType = "non-existent"
Case DRIVE_CDROM
DriveType = "CD-ROM"
Case DRIVE_FIXED
DriveType = "local"
Case DRIVE_RAMDISK
DriveType = "RAM"
Case DRIVE_REMOTE
DriveType = "remote"
Case DRIVE_REMOVABLE
DriveType = "removeable"
End Select
Exit Function
End Function
Check if file and/or folder exists, more than one flash may be plugged in
Drive B could also show as removable
thnx to all of u guys....
to isnoend07:
Thank you for that code.. it works
1. may i know why u put "For I = 65 To 90"?
2. what if there is other flash disk that already plug in?
65 to 90 is a to z,
when i am looking for usb drive i start at the highest drive letter and work backwards as usb drives are normally after all fixed drives and cd drives, i also don't check for drives c: and below
as isnoend said check some content on the drive (or drive label) to confirm it it is the correct one
Returns aString containing the character associated with the specified character code.Quote:
Originally Posted by Noob_Coder
Dim MyChar
MyChar = Chr(65) ' Returns A.
MyChar = Chr(66) ' Returns B.
MyChar = Chr(67) ' Returns C.
etc
as westconn1 suggested you may want to loop backwards and skip to Chr(68)
Eg
For I = 90 To 68
To check if more than flash is plugged in search for a file or folder that you know exists on each flash if not found you may want to prompt the user and create the folder or file of course then you will have to check for usable space., Like is the Flash drive full. also you could run into the situation where
the same file or folder is on more than 1 flash drive, then you would also prompt the user to remove one You will also need to check if no flash is plugged in and prompt the user. I have been working on a file backup and restore and am dealing with all these variables. User could also have a bunch
of flash drives plugged in.
Good luck
Not exactly sure but you may also want to fiddle with this...