From: Larry Serflaten on

"LondonLad" <LondonLad(a)discussions.microsoft.com> wrote
> Hi
> Finding all files with named extn on a single drive I have no problems with
> , but can someone give me a link to helpful code so I can find all files with
> named extn on all drives on my computer.

This may or may not suit your needs, you decide....

Add a command button to a new form and paste in the code below to
try it out....

LFS

-------------------

Private Sub Command1_Click()
Dim WMI, QRY, ITEM
On Error Resume Next
Set WMI = GetObject("winmgmts://./root/cimv2")
If Err.Number Then
MsgBox "WMI not available."
Else
QRY = "SELECT Name FROM Win32_LogicalDisk WHERE Description = 'Local Fixed Disk'"
For Each ITEM In WMI.ExecQuery(QRY, "WQL", &H30)
Searching ITEM.Name
Next
End If
End Sub

Sub Searching(DriveName As String)
'your search code goes here
MsgBox "Searching for files on drive " & DriveName, vbOKOnly, "Search Mode"
End Sub


From: Larry Serflaten on

"Larry Serflaten" <serflaten(a)gmail.com> wrote

> QRY = "SELECT Name FROM Win32_LogicalDisk WHERE Description = 'Local Fixed Disk'"

Oops, you said 'all drives' and the above only returns the hard drives.
If you want ALL drives, remove the WHERE clause:

> QRY = "SELECT Name FROM Win32_LogicalDisk"

HTH
LFS


From: Tony Toews on
On Tue, 6 Jul 2010 08:47:55 -0700, "Bob Butler"
<bob_butler(a)cox.invalid> wrote:

>> Easy enough with some help from the API.
>> First you need GetLogicalDriveStrings which will return a list of all
>> drives on the PC, you split this in whatever way you like.
>> The use GetDriveType on each returned letter to check that it's a volume
>> on a local hard drive.
>
>I've always just looped A-Z and used GetDriveType to skip ones that don't
>exist. I've never found a good reason to use GetLogicalDriveStrings. Apart
>from maybe saving a few milliseconds is there anything else it provides?

Is there a difference if some drive letters aren't connected to a
network? Possibly GetLogicalDriveStrings would ignore those.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
From: Tony Toews on
On Tue, 6 Jul 2010 07:44:26 -0700, LondonLad
<LondonLad(a)discussions.microsoft.com> wrote:

>Finding all files with named extn on a single drive I have no problems with
>, but can someone give me a link to helpful code so I can find all files with
>named extn on all drives on my computer.

Do you means just drive letters, such as USB drives, external hard
drives or various cards? Does this include network drive letters or
network shared folders?

Toy
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
From: Bob Butler on

"Tony Toews" <ttoews(a)telusplanet.net> wrote in message
news:jh2736pikeevjqoqelfokfa5mk6iebpn47(a)4ax.com...
> On Tue, 6 Jul 2010 08:47:55 -0700, "Bob Butler"
> <bob_butler(a)cox.invalid> wrote:
>
>>> Easy enough with some help from the API.
>>> First you need GetLogicalDriveStrings which will return a list of all
>>> drives on the PC, you split this in whatever way you like.
>>> The use GetDriveType on each returned letter to check that it's a volume
>>> on a local hard drive.
>>
>>I've always just looped A-Z and used GetDriveType to skip ones that don't
>>exist. I've never found a good reason to use GetLogicalDriveStrings.
>>Apart
>>from maybe saving a few milliseconds is there anything else it provides?
>
> Is there a difference if some drive letters aren't connected to a
> network? Possibly GetLogicalDriveStrings would ignore those.

That's the point. GetLogicalDriveLetters returns just those drives in use
but it's just as easy to check all 26 letters and ignore those that return
'no drive found' as it is to ask for the list of valid drives and then
process only them (and still having to check in case one disconnects while
processing the list).

Getting the list of drives is probably the "right" way to do it but I've
just never bothered.