Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

VS 2012 Listbox + files searching help

$
0
0
So I have been playing with this for about a week not sure how to fix it or get it to work how I want it to.

I am able to search all my folders and files on my desktop. fine with this code

Private Sub listfiles(ByVal [path] As String)
Dim dirinfo As New DirectoryInfo(path)
Dim fileobj As IO.FileSystemInfo


For Each fileobj In dirinfo.GetFileSystemInfos'("*.jpg")
If fileobj.Attributes = FileAttributes.Directory Then
listfiles(fileobj.FullName)
ListBox1.Items.Add(fileobj.FullName)
Dim diar1 As IO.FileInfo() = dirinfo.GetFiles("*.jpg")
Dim dra As IO.FileInfo
For Each dra In diar1
ListBox2.Items.Add(dra)
Next

Else

Me.ListBox7.Items.Add(fileobj.FullName)

End If

Next
End Sub


Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

listfiles("C:\Users\Rob\Desktop\")
'Me.FolderBrowserDialog1.ShowDialog()
'listfiles(Me.FolderBrowserDialog1.SelectedPath)

End Sub

listbox 7 shows all files from the desktop and subolders
listbox1 shows all folders
listbox2 should show all jpg

the problem it its not showing them all jpgs and its showing some files/jpgs 5-15 times in listbox2

i am sure i can and will clean this code up a bit its getting quite messy with me adding/removing/moving thing around.
I do not really need those other list box all i really care about are jpgs showing up in a listbox. those others are there for me trouble shooting the files showing up in multiples and not showing up.
I do have 1 other Q not as important i have not researched this as much but how do i place a wildcard in a file path. so like if i used this on another PC it would do the same to there desktop. I think its in my VB book i have just have to dig it out of a box (i just moved)

Thanks for any help guys

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>