Sinisterly
[VB.Net] Making a cool File/Directory Search - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.Net] Making a cool File/Directory Search (/Thread-VB-Net-Making-a-cool-File-Directory-Search)

Pages: 1 2 3 4


[VB.Net] Making a cool File/Directory Search - Coder-san - 12-07-2010

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


RE: [VB.Net] Making a cool File/Directory Search - 1234hotmaster - 12-07-2010

nice program will be handy for quick searches Smile


RE: [VB.Net] Making a cool File/Directory Search - 1llusion - 12-10-2010

I was searching for this!!! Thanks Smile now my html/txt injector is complete!!!


RE: [VB.Net] Making a cool File/Directory Search - Coder-san - 12-10-2010

No problem, glad it could help you. Smile
By the way, that is also an example for how to use a Progressbar correctly.


RE: [VB.Net] Making a cool File/Directory Search - rapidguide - 01-01-2011

NICE , THX FOR SHARE KEEP IT UP


RE: [VB.Net] Making a cool File/Directory Search - Coder-san - 03-22-2013

(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 (*.*).


RE: [VB.Net] Making a cool File/Directory Search - ArkPhaze - 03-24-2013

Why do you have this in the loop?
Code:
Threading.Thread.Sleep(10)



RE: [VB.Net] Making a cool File/Directory Search - ArkPhaze - 03-24-2013

Why do you have this in the loop?
Code:
Threading.Thread.Sleep(10)



RE: [VB.Net] Making a cool File/Directory Search - Coder-san - 03-24-2013

(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.


RE: [VB.Net] Making a cool File/Directory Search - Coder-san - 03-24-2013

(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.