SearchOption 열거형

정의

현재 디렉터리를 검색할 것인지 또는 현재 디렉터리와 모든 하위 디렉터리를 검색할 것인지 여부를 지정합니다.Specifies whether to search the current directory, or the current directory and all subdirectories.

public enum class SearchOption
public enum SearchOption
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum SearchOption
type SearchOption = 
Public Enum SearchOption
상속
SearchOption
특성

필드

AllDirectories 1

검색 작업에 현재 디렉터리와 모든 하위 디렉터리를 포함합니다.Includes the current directory and all its subdirectories in a search operation. 이 옵션을 지정하면 탑재된 드라이브 및 심볼 링크와 같은 재분석 지점이 검색에 포함됩니다.This option includes reparse points such as mounted drives and symbolic links in the search.

TopDirectoryOnly 0

검색 작업에 현재 디렉터리만 포함합니다.Includes only the current directory in a search operation.

예제

다음 예제에서는 "c:\"와 같이 문자 "c"로 시작 하는 모든 디렉터리와 파일을 나열 합니다.The following example lists all the directories and files that begin with the letter "c", as in "c:\". 이 예에서는 TopDirectoryOnly를 사용 하 여 최상위 디렉터리만 검색 하도록 지정 합니다.In this example, TopDirectoryOnly is used to specify that only the top-level directory should be searched.

using namespace System;
using namespace System::IO;

ref class App
{
public:
    static void Main()
    {
        // Specify the directory you want to manipulate.
        String^ path = "c:\\";
        String^ searchPattern = "c*";

        DirectoryInfo^ di = gcnew DirectoryInfo(path);
        array<DirectoryInfo^>^ directories =
            di->GetDirectories(searchPattern, SearchOption::TopDirectoryOnly);

        array<FileInfo^>^ files =
            di->GetFiles(searchPattern, SearchOption::TopDirectoryOnly);

        Console::WriteLine(
            "Directories that begin with the letter \"c\" in {0}", path);
        for each (DirectoryInfo^ dir in directories)
        {
            Console::WriteLine(
                "{0,-25} {1,25}", dir->FullName, dir->LastWriteTime);
        }

        Console::WriteLine();
        Console::WriteLine(
            "Files that begin with the letter \"c\" in {0}", path);
        for each (FileInfo^ file in files)
        {
            Console::WriteLine(
                "{0,-25} {1,25}", file->Name, file->LastWriteTime);
        }
    } // Main()
}; // App()

int main()
{
    App::Main();
}
using System;
using System.IO;

class App
{
    public static void Main()
    {
        // Specify the directory you want to manipulate.
        string path = @"c:\";
        string searchPattern = "c*";

        DirectoryInfo di = new DirectoryInfo(path);
        DirectoryInfo[] directories = 
            di.GetDirectories(searchPattern, SearchOption.TopDirectoryOnly);

        FileInfo[] files = 
            di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly);

        Console.WriteLine(
            "Directories that begin with the letter \"c\" in {0}", path);
        foreach (DirectoryInfo dir in directories)
        {
            Console.WriteLine(
                "{0,-25} {1,25}", dir.FullName, dir.LastWriteTime);
        }

        Console.WriteLine();
        Console.WriteLine(
            "Files that begin with the letter \"c\" in {0}", path);
        foreach (FileInfo file in files)
        {
            Console.WriteLine(
                "{0,-25} {1,25}", file.Name, file.LastWriteTime);
        }
    } // Main()
} // App()
Imports System.IO

Class App
    Public Shared Sub Main()
        ' Specify the directory you want to manipulate.
        Dim path As String = "c:\\"
        Dim searchPattern As String = "c*"

        Dim di As DirectoryInfo = New DirectoryInfo(path)
        Dim directories() As DirectoryInfo = _
            di.GetDirectories(searchPattern, SearchOption.TopDirectoryOnly)

        Dim files() As FileInfo = _
            di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly)

        Console.WriteLine( _
            "Directories that begin with the letter 'c' in {0}", path)
        Dim dir As DirectoryInfo
        For Each dir In directories
            Console.WriteLine( _
                "{0,-25} {1,25}", dir.FullName, dir.LastWriteTime)
        Next dir

        Console.WriteLine()
        Console.WriteLine( _
            "Files that begin with the letter 'c' in {0}", path)
        Dim file As FileInfo
        For Each file In files
            Console.WriteLine( _
                "{0,-25} {1,25}", file.Name, file.LastWriteTime)
        Next file
    End Sub
End Class

설명

검색에서 AllDirectories를 선택 하 고 디렉터리 구조에 루프를 만드는 링크가 포함 된 경우 검색 작업은 무한 루프로 들어갑니다.If you choose AllDirectories in your search and the directory structure contains a link that creates a loop, the search operation enters an infinite loop.

적용 대상