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





Messages In This Thread
[VB.Net] Making a cool File/Directory Search - by Coder-san - 12-07-2010, 02:30 PM



Users browsing this thread: