|
-
Mar 10th, 2002, 07:04 AM
#1
Thread Starter
New Member
Drive letters and identification
I want to search a single drive specified by the user or all drives if the user de-selects the check box to limit to a single drive.
However, I want the all drive search to limit to Hard Disks only (ignoring Floppies and CD's, zip drives etc). I have visualised a function which returns a string containing only the letters of the hard disks on the PC. I can then use this string to perform a search and update a database of specific files when it finds them.
I am pretty sure that there is an API call to do this but I can't find any information about it and it's got me pulling my hair out.
-
Mar 10th, 2002, 08:52 AM
#2
Hopefully this will help get you started
VB Code:
Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
Private Sub GetDrives(CB As ComboBox, ByVal IsUsed As Boolean)
Dim DriveLtr As Long
Dim StartPos As Integer
If IsUsed = True Then 'if True is returned, then we want
StartPos = 0 'all drive letters in use
Else
StartPos = 4 'if False is returned, then we want
End If 'to find an unused network drive, so
'skip A:, B:, C:, and D:
CB.Clear
For DriveLtr =StartPos To 25
If CBool(GetLogicalDrives And (2 ^ DriveLtr)) = IsUsed Then
CB.AddItem Chr$(Asc("A") + DriveLtr) & ":"
'To check to see if a drive is already mapped, add this code
'If Chr$(Asc("A") + DriveLtr) = "W" Then
' MsgBox "here it is"
'End If
End If
Next
'To Use: GetDrives Combo1, True returns all drives letters currently in use
' GetDrives Combo1, False returns all available drive letters
End Sub
-
Mar 10th, 2002, 10:50 AM
#3
Thread Starter
New Member
@ Hack
Thanks for that. I knew there was a way to do it but I didn't realise it was a Kernel32 call. There was my error, I was searching through the extensive list of API calls.... in the wrong libraries.
And there was me thinking I had a brain DOH!
But I have one additional Question with regard to the code. The help tells me that I have to use the DriveType Constant to identify Hard Disks only by using
For DriveLtr =StartPos To 25
If CBool(GetLogicalDrives And (2 ^ DriveLtr)) = IsUsed Then
If DriveType = 2 Then
"'anything that gets past here is a hard disk
CB.AddItem Chr$(Asc("A") + DriveLtr) & ":"
End If
End If
Next DriveLtr
DriveType is located in the VB6.OLB Which has to be included... HOW?
I have tried to view it in Notepad but it isn't even a txt file so I can't cut & paste. It won't add as a module and I can't even use "add File
Last edited by Tryst; Mar 10th, 2002 at 06:10 PM.
-
Mar 10th, 2002, 06:52 PM
#4
An OLB is an object library which can be referenced. When you put together your setup and installation package, that library will be included.
-
Mar 10th, 2002, 06:58 PM
#5
Thread Starter
New Member
Thanks again. I have included the reference now and I can only hope that it works now 
You would have thought MS would have made things a little easier.
-
Mar 10th, 2002, 07:02 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|