Get default drive and list files and files in subfolders

Hi,

Without using a DriveBox or FileList box, and also without using Microsoft's new filesysinfo dll (or whatever it's called, which ships with VB6) I want to be able to ascertain the users default drive, and get the name of each *.bmp file in that drive and in all subfolders.

Many thanks,
Dave
LVL 1
dgb001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SiM99Commented:
use the Dir$() function... look it up in the help and it will show you what to do with it.

Sorry for the lack of input (no example) but the computer i'm on doesn't have VB installed on it.

The idea is to do a loop, using Dir() to get a filename, checking the return type to see ie it's a DIR or FILE, then if it's a file, do

if (right(filename, 4) = ".bmp") then

again, sorry that i cannot give an example, but i could do if you want me to, just say so :)
0
dgb001Author Commented:
OK, thx, I'll take a look and let you know.

Cheers,
Dave
0
VbmasterCommented:
Here's a function you can use.. you call it using code like


  Dim File As New clsFile
  Dim x() As String
  Dim a As Integer
 
  Call File.ListFiles("C:\", x, True, True, "*.bmp")
  Debug.Print ""
  Debug.Print Now
  For a = 1 To UBound(x)
    Debug.Print x(a)
  Next


And the function is..

Function ListFiles(ByVal Path As String, ByRef av_Array() As String, Recursive As Boolean, Optional IncludePaths As Boolean = True, Optional Prefix As String = "*.*", Optional ByRef x As Double = 0, Optional StartDir As Boolean = True)

  Dim MyName  As String
  Dim MyDir() As String
  Dim MyDirNr As Integer
  Dim a       As Integer
 
  MyDirNr = 0
  If StartDir Then
    x = 0
    Path = IIf(Right$(Path, 1) = "\", Path, Path & "\")
    Prefix = UCase$(Prefix)
  End If
 
  On Error GoTo Errorhandler
 
  MyName = Dir$(Path & "*.*", vbDirectory + vbArchive + vbHidden + vbReadOnly + vbSystem)
  Do While (Len(MyName) > 0)
    If (MyName <> ".") And (MyName <> "..") Then
      If (GetAttr(Path & MyName) And vbDirectory) = vbDirectory Then
        ReDim Preserve MyDir(MyDirNr + 1)
        MyDirNr = MyDirNr + 1
        MyDir(MyDirNr) = MyName
      ElseIf (UCase$(MyName) Like Prefix) Then
        If (x Mod 10 = 0) Then ReDim Preserve av_Array(x + 10)
        x = x + 1
        If IncludePaths Then
          av_Array(x) = Path & MyName
        Else
          av_Array(x) = MyName
        End If
      End If
    End If
    MyName = Dir$
  Loop
 
  If Recursive Then
    For a = 1 To MyDirNr
      If Not ListFiles(Path & MyDir(a) & "\", av_Array(), True, IncludePaths, Prefix, x, False) Then GoTo Errorhandler
    Next
  End If
  If StartDir Then ReDim Preserve av_Array(x)
  ListFiles = True
  Exit Function
 
Errorhandler:
  ListFiles = False

End Function

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

dgb001Author Commented:
Ok, let me have a read and play with it and I'll get back to you.

Many thx,
Dave
0
dgb001Author Commented:
Hi,

Just a couple of things:

a) I seem to get a "User-defined type not defined" on the first line when it tries to Dim clsFile

b) I notice that you defaulted it to use C:\ - is there a way to find out if that is indeed the default drive ?

Many thx,
Dave
0
SiM99Commented:
you need the class file called clsFile
0
VbmasterCommented:
Oops remove the line..

  Dim File As New clsFile

and change the function call from..

  Call File.ListFiles("C:\", x, True, True, "*.bmp")

to..

  Call ListFiles("C:\", x, True, True, "*.bmp")
0
VbmasterCommented:
To get the current drive you can use the CurDir variable, where the current drive is Left$(CurDir, 3)
0
dgb001Author Commented:
Okey dokey - let me play around and I'll get back to you.

Thx for your help,
Dave
0
dgb001Author Commented:
Thx,
Dave
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.