GoGreen PC TuneUp™
Learn More

Insta-Install™
this is how we code sign our software and ssl encrypt our websites from our affiliate partner SSL.com
MTNCOMP | List | Table

myBlog

myBlog Home

Blog


VB.Net example using System.IO and how to process all files (txt) on a drive

by Mountain Computers Inc., Publication Date: Monday, October 19, 2020
View Count: 197, Keywords: VB.Net, System.IO, File Directory Search, Sample, Hashtags: #VB.Net #System.IO #FileDirectorySearch #Sample



 
Just looking for an example for a tool I am writing. This gets me close. I changed a little bit of it so it can run in parallelism. This actually works. in your code, just call RecursiveSearch(). This is an excerpt from a console app, so you can comment / rem out the console.readkey() near the bottom.
 
My 3950x does spike in my own example for running in MPP mode.
 
more to come...
 
 
REF:  https://stackoverflow.com/questions/46889375/vb-net-need-help-enumerating-files-fast-on-entire-c-drive
Imports System.IO
Sub RecursiveSearch()
Dim searcher As New Task(Of IList(Of String))(Function()
Return GetFiles("C:\", "*.txt")
End Function)
searcher.Start()
Console.WriteLine("Searching for .txt files in C:\ and all subdirectories...")
searcher.Wait()
Dim files = searcher.Result
Console.WriteLine(String.Format("{0:N0} .txt files found.", files.Count))
Console.ReadKey()
End Sub

Function GetFiles(directoryPath As String, filter As String) As IList(Of String)
Dim files As New List(Of String)
Dim directories() As String = Nothing
Try
files.AddRange(Directory.GetFiles(directoryPath, filter))
directories = Directory.GetDirectories(directoryPath)
Catch ex As Exception
Console.WriteLine($"Error while processing folder {directoryPath}.")
End Try
If directories IsNot Nothing Then
For Each directory In directories
files.AddRange(GetFiles(directory, filter))
Next
End If
Return files
End Function

 

if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.

© 2021 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.