.NET Framework Class Library  

DirectoryInfo.GetFileSystemInfos Method

Retrieves an array of strongly typed FileSystemInfo objects.

Overload List

Returns an array of strongly typed FileSystemInfo entries listing all the files and directories.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetFileSystemInfos() As FileSystemInfo()
[C#] public FileSystemInfo[] GetFileSystemInfos();
[C++] public: FileSystemInfo* GetFileSystemInfos() [];
[JScript] public function GetFileSystemInfos() : FileSystemInfo[];

Retrieves an array of strongly typed FileSystemInfo objects matching the specified search criteria.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetFileSystemInfos(String) As FileSystemInfo()
[C#] public FileSystemInfo[] GetFileSystemInfos(string);
[C++] public: FileSystemInfo* GetFileSystemInfos(String*) [];
[JScript] public function GetFileSystemInfos(String) : FileSystemInfo[];

Example

[Visual Basic, C#, C++] The following example counts the files and directories that match the specified search pattern.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetFileSystemInfos. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        ' Specify the directories you want to manipulate.
        Dim di As DirectoryInfo = New DirectoryInfo("c:\")
        Try
            ' Get only subdirectories that contain the letter "p."
            Dim dirs As FileSystemInfo() = di.GetDirectories("*p*")
            Console.WriteLine("Number of directories with a p: {0}", dirs.Length)
            Dim diNext As DirectoryInfo

            ' Count all the files in each subdirectory that contain the letter "e."
            For Each diNext In dirs
                Console.WriteLine("The number of files and directories " + _
                 "in {0} with an e is {1}", diNext, _
                 diNext.GetFileSystemInfos("*e*").Length)
            Next
        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class

[C#] 
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            DirectoryInfo di = new DirectoryInfo(@"c:\");
            // Get only subdirectories that contain the letter "p."
            FileSystemInfo[] dirs = di.GetDirectories("*p*");
            Console.WriteLine("Number of directories with a p: {0}", dirs.Length);
            // Count all the files in each subdirectory that contain the letter "e."
            foreach (DirectoryInfo diNext in dirs) 
            {
                Console.WriteLine("The number of files and directories " +
                    "in {0} with an e is {1}", diNext, 
                    diNext.GetFileSystemInfos("*e*").Length);
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::IO;

void main() {
    try {
        DirectoryInfo* di = new DirectoryInfo(S"c:\\");
        // Get only subdirectories that contain the letter S"p."
        FileSystemInfo* dirs[] = di->GetDirectories(S"*p*");
        Console::WriteLine(S"Number of directories with a p: {0}", __box(dirs->Length));
        // Count all the files in each subdirectory that contain the letter "e."
        Collections::IEnumerator* myEnum = dirs->GetEnumerator();
        while (myEnum->MoveNext()) {
            DirectoryInfo* diNext = __try_cast<DirectoryInfo*>(myEnum->Current);

            Console::WriteLine(S"The number of files and directories in {0} with an e is {1}", diNext, 
                __box(diNext->GetFileSystemInfos(S"*e*")->Length));
        }
    } catch (Exception* e) {
        Console::WriteLine(S"The process failed: {0}", e);
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DirectoryInfo Class | DirectoryInfo Members | System.IO Namespace