Login Register






[VB.Net] Making a cool File/Directory Search filter_list
Author
Message
[VB.Net] Making a cool File/Directory Search #1
Searching Directories and Sub-directories:
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]

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) Next

That's all for now, happy coding. Smile
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB.Net] Making a cool File/Directory Search #2
nice program will be handy for quick searches Smile
Pierce the life fibers with your drill.

Reply

RE: [VB.Net] Making a cool File/Directory Search #3
I was searching for this!!! Thanks Smile now my html/txt injector is complete!!!
Staff will never ever ask you for your personal information.
We know everything about you anyway.

Reply

RE: [VB.Net] Making a cool File/Directory Search #4
No problem, glad it could help you. Smile
By the way, that is also an example for how to use a Progressbar correctly.
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB.Net] Making a cool File/Directory Search #5
NICE , THX FOR SHARE KEEP IT UP

Reply

RE: [VB.Net] Making a cool File/Directory Search #6
(03-21-2013, 02:44 AM)404hacker Wrote: you have not declared strpath and i cant see any codes for the combobox there can you please help me

Iirc the strPath is supposed to be the combobox. Why not a textbox? Because it can be used to show the history of last searched items.
The textbox was probably used for extensions. In the snippet it's hard-coded to search for all extensions (*.*).
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB.Net] Making a cool File/Directory Search #7
Why do you have this in the loop?
Code:
Threading.Thread.Sleep(10)
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [VB.Net] Making a cool File/Directory Search #8
Why do you have this in the loop?
Code:
Threading.Thread.Sleep(10)
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [VB.Net] Making a cool File/Directory Search #9
(03-24-2013, 06:17 AM)ArkPhaze Wrote: Why do you have this in the loop?
Code:
Threading.Thread.Sleep(10)

It's an old code, I don't know why I put that.
The app will stop responding because of the frequent update of the ListView, so probably a lazy way to prevent it. Not sure.
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: [VB.Net] Making a cool File/Directory Search #10
(03-24-2013, 06:17 AM)ArkPhaze Wrote: Why do you have this in the loop?
Code:
Threading.Thread.Sleep(10)

It's an old code, I don't know why I put that.
The app will stop responding because of the frequent update of the ListView, so probably a lazy way to prevent it. Not sure.
[Image: rytwG00.png]
Redcat Revolution!

Reply