in

vbCity Blogs

New (temp) place for vbCity Blogs

Mike McIntyre's .NET Journal

Search for Files with a Specific Extension in and below a System Special Folder

The Visual Basic My.Computer.FileSystem GetFiles method can be used to search for files with a specific extension in or below a specific directory:

Below is a function for that purpose:

    Private Function GetFilePathList(ByVal specialDirectoryPath As String, ByVal fileExtension As String) _
                    As List(Of String)
        ' Instantiate a list of type String.
        Dim filePathList As New List(Of String)
        ' Use the My.Computer.FileSystem GetFiles method to search for files with a specific file
        '   extension in or below a specific directory.
        ' Note the use of the FileIO.SearchOption SearchAllSubDirectories to request all directories
        '   below the specifified directory be searched too.
        For Each filePath As String In My.Computer.FileSystem.GetFiles(specialDirectoryPath, _
                    FileIO.SearchOption.SearchAllSubDirectories, fileExtension)
            filePathList.Add(filePath)
        Next
        Return filePathList
    End Function

Here's an example show how to call the function above:

Dim fileList As List(Of String) = GetFilePathList(My.Computer.FileSystem.SpecialDirectories.MyPictures, "*.png")

 

Mike McIntyre's .Net Journal

getdotnetcode.com

Only published comments... Oct 14 2009, 07:19 PM by Mike McIntyre
Filed under:

About Mike McIntyre

I  am a programmer, developer, and system architect with 29+years experience including state-of-the-art application development frameworks and languages including Visual Studio versions 2002-2010, .NET Framework versions 1-4, C#, and Visual Basic.

I am a mentor, trainer, and coach in the Microsoft .NET technical community. DevCity is my favorite community site. You can find examples of my involvement with DevCity in the site articles, newsletter articles, and my posts in the forum.

Since 2002 I have hosted a .NET site at http://www.getdotnetcode.com, a place with free and inexpensive Visual Basic and C# source code that can be purchased on an 'as needed' basis.

In 2007 I established a .NET search engine, 'Resources for .NET Developers' at http://dot-net-resources-swicki.eurekster.com

Copyright 1998-2009 vbCity.com LLC
Powered by Community Server (Non-Commercial Edition), by Telligent Systems