We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to search a disk for files?

Olli083097
Olli083097 asked
on
Medium Priority
285 Views
Last Modified: 2010-05-03
Can someone provide me with some code to use searching thrugh a disk for files?
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
Olli,
This is a routine searching a directory for all the files.
If you have questions, let me know
Regards
Dalin




    Private Sub cmdGetFileList_Click()

    Dim myFile As String
    Dim myPath As String
    Dim iposition As Integer

    myPath = "C:\YourDirectory\"

    myFile = Dir(myPath, vbDirectory)   ' Retrieve the first entry.
    Do While myFile <> ""   ' Start the loop.
        ' Ignore the current directory and
        If myFile <> "." And myFile <> ".." Then
             
            If (GetAttr(myPath & myFile) And vbDirectory) = vbDirectory Then
               ' a Sub Directory, Do nothing,
            Else
               iposition = InStr(1, myFile, ".")
               myFile = Left(myFile, iposition - 1)
               List1.AddItem myFile
                           
            End If  ' it represents a directory.
        End If
        myFile = Dir    ' Get next entry.
    Loop

    End sub



Dr. Kamal MehdiIT Director / IT Project Manager
CERTIFIED EXPERT

Commented:
Olli,
There is a sample project for searching the disk for files. It is loacted under your VB directory in \samples\filectls (winseek.vbp).

Author

Commented:
Thank you all for trying to help!
swilt: Your code was just what I needed.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.