Question Searching Hard Disk For Files..

Sachith

Member
Joined
Jan 17, 2011
Messages
11
Location
Sri Lanka
Programming Experience
3-5
I am going to develop a antivirus software and i want to scan the files..
so i want to get the files one by one into a Label

I Already use this code to get add the files to a listbox But It did not Help For me...
Because it is adding Whole Files to a List Box at Ones..

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        rslts = New List(Of String)
        foo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
        ListBox1.Items.Clear()
        ListBox1.Items.AddRange(rslts.ToArray)

    End Sub

    Dim rslts As List(Of String)

    Private Sub foo(ByVal aDir As String)
        Try

            Dim di As New IO.DirectoryInfo(aDir)
            Dim aryFiles() As IO.FileInfo = di.GetFiles("*.*")
            Dim aryDirs() As IO.DirectoryInfo = di.GetDirectories()

            For Each fi As IO.FileInfo In aryFiles
                rslts.Add(fi.FullName)
            Next

            For Each d As IO.DirectoryInfo In aryDirs
                foo(d.FullName)
            Next

        Catch ex As Exception
           
        End Try

    End Sub


If Enyone Know How To Do this.. Please Help Me..
I Been Searching For this Since last Month.. Thanks..
 
Last edited by a moderator:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,728
Location
Sydney, Australia
Programming Experience
10+
First up, 'foo' is a name that people use for methods in example code when when they don't actually do anything. Your method has a specific purpose so its name should reflect that.

As for the question, just don't add the file name to the list. At that point, display the file name in the Label and then call the method that will scan that file.
 
Top Bottom