[VB.Net] Making a cool File/Directory Search 12-07-2010, 02:30 PM
#1
Searching Directories and Sub-directories:
Files in Directories and sub-directories:
The SearchOption is currently AllDirectories, if you just want to limit it to the Top Directories then change the SearchOption.
Note: You will need a ListBox named ListBox1 for testing the above code.
Making a Cool File search
![[Image: FileSearch.png]](http://b.imagehost.org/0391/FileSearch.png)
Controls needed:
This is all the code you need in a button click event.
That's all for now, happy coding.
Code:
ListBox1.Items.AddRange(Directory.GetDirectory("C:\Program Files", SearchOption.AllDirectories))Files in Directories and sub-directories:
Code:
ListBox1.Items.AddRange(Directory.GetFiles("C:\Program Files", "*.*", SearchOption.AllDirectories))The SearchOption is currently AllDirectories, if you just want to limit it to the Top Directories then change the SearchOption.
Note: You will need a ListBox named ListBox1 for testing the above code.
Making a Cool File search
![[Image: FileSearch.png]](http://b.imagehost.org/0391/FileSearch.png)
Controls needed:
- ImageList (iconList)
ColorDepth = Depth32Bit
ImageSize = 32, 32
- ListView (ListView1)
Add 3 Coloumns (Filename, Size, Path)
View = Details
SmallImageList = iconList
- ComboBox (ComboBox1)
- TextBox (TextBox2)
- ProgressBar (ProgressBar1)
- Label (Label1)
- A Button for running the code
This is all the code you need in a button click event.
Code:
For Each Item As String In IO.Directory.GetFiles(strPath, "*.*", IO.SearchOption.AllDirectories)
'Add file icons to our ImageList
iconList.Images.Add(Icon.ExtractAssociatedIcon(Item))
With ListView1.Items
'Strip the Filename from the Full file path
.Add(Item.Substring(Item.LastIndexOf("\") + 1), iconList.Images.Count - 1)
'.Add(IO.Path.GetFileNameWithoutExtension(Item))
'Add File size to second coloumn
.Item(.Count - 1).SubItems.Add(Math.Round(FileLen(Item) / 1048576, 1) & " MB")
'Add Full path to third coloumn
.Item(.Count - 1).SubItems.Add(Item)
'Show current Progress
ProgressBar1.Value = .Count
End With
'Show current Progress in Label
Label1.Text = ProgressBar1.Value & " / " & ProgressBar1.Maximum & " Files found"
Threading.Thread.Sleep(10)
NextThat's all for now, happy coding.
![[Image: rytwG00.png]](http://i.imgur.com/rytwG00.png)
Redcat Revolution!

![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)