Directory.GetFileSystemEntries Metoda

Definicja

Zwraca nazwy wszystkich plików i podkatalogów spełniających określone kryteria.

Przeciążenia

GetFileSystemEntries(String)

Zwraca nazwy wszystkich plików i podkatalogów w określonej ścieżce.

GetFileSystemEntries(String, String)

Zwraca tablicę nazw plików i nazw katalogów, które pasują do wzorca wyszukiwania w określonej ścieżce.

GetFileSystemEntries(String, String, EnumerationOptions)

Zwraca tablicę nazw plików i nazw katalogów, które pasują do wzorca wyszukiwania i opcji wyliczenia w określonej ścieżce.

GetFileSystemEntries(String, String, SearchOption)

Zwraca tablicę wszystkich nazw plików i nazw katalogów pasujących do wzorca wyszukiwania w określonej ścieżce i opcjonalnie wyszukuje podkatalogi.

GetFileSystemEntries(String)

Źródło:
Directory.cs
Źródło:
Directory.cs
Źródło:
Directory.cs

Zwraca nazwy wszystkich plików i podkatalogów w określonej ścieżce.

public:
 static cli::array <System::String ^> ^ GetFileSystemEntries(System::String ^ path);
public static string[] GetFileSystemEntries (string path);
static member GetFileSystemEntries : string -> string[]
Public Shared Function GetFileSystemEntries (path As String) As String()

Parametry

path
String

Ścieżka względna lub bezwzględna do katalogu do wyszukania. W tym ciągu nie jest rozróżniana wielkość liter.

Zwraca

String[]

Tablica nazw plików i podkatalogów w określonym katalogu lub pusta tablica, jeśli nie znaleziono plików lub podkatalogów.

Wyjątki

Obiekt wywołujący nie posiada wymaganych uprawnień.

.NET Framework i .NET Core w wersjach starszych niż 2.1: path jest ciągiem o zerowej długości, zawiera tylko biały znak lub zawiera co najmniej jeden nieprawidłowy znak. Możesz wykonać zapytanie o nieprawidłowe znaki za pomocą polecenia GetInvalidPathChars().

path to null.

Podana ścieżka, nazwa pliku lub obie przekraczają maksymalną długość zdefiniowaną przez system.

path to nazwa pliku.

Określona ścieżka jest nieprawidłowa (na przykład znajduje się na niezamapowanym dysku).

Przykłady

W poniższym przykładzie użyto GetFileSystemEntries metody , aby wypełnić tablicę ciągów nazwami wszystkich plików i podkatalogów w określonej przez użytkownika lokalizacji i drukuje każdy ciąg w tablicy do konsoli. W tym przykładzie skonfigurowano przechwytywanie wszystkich błędów typowych dla tej metody.

using namespace System;
class Class1
{
public:
   void PrintFileSystemEntries( String^ path )
   {
      try
      {
         
         // Obtain the file system entries in the directory path.
         array<String^>^directoryEntries = System::IO::Directory::GetFileSystemEntries( path );
         for ( int i = 0; i < directoryEntries->Length; i++ )
         {
            System::Console::WriteLine( directoryEntries[ i ] );

         }
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, \HelloServer'                  or contains invalid characters." );
      }
      catch ( System::IO::DirectoryNotFoundException^ ) 
      {
         System::Console::WriteLine(  "The path encapsulated in the \HelloServer'                  Directory object does not exist." );
      }

   }

   void PrintFileSystemEntries( String^ path, String^ pattern )
   {
      try
      {
         
         // Obtain the file system entries in the directory
         // path that match the pattern.
         array<String^>^directoryEntries = System::IO::Directory::GetFileSystemEntries( path, pattern );
         for ( int i = 0; i < directoryEntries->Length; i++ )
         {
            System::Console::WriteLine( directoryEntries[ i ] );

         }
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, \HelloServer'                  or contains invalid characters." );
      }
      catch ( System::IO::DirectoryNotFoundException^ ) 
      {
         System::Console::WriteLine(  "The path encapsulated in the \HelloServer'                  Directory object does not exist." );
      }

   }


   // Print out all logical drives on the system.
   void GetLogicalDrives()
   {
      try
      {
         array<String^>^drives = System::IO::Directory::GetLogicalDrives();
         for ( int i = 0; i < drives->Length; i++ )
         {
            System::Console::WriteLine( drives[ i ] );

         }
      }
      catch ( System::IO::IOException^ ) 
      {
         System::Console::WriteLine(  "An I/O error occurs." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }

   }

   void GetParent( String^ path )
   {
      try
      {
         System::IO::DirectoryInfo^ directoryInfo = System::IO::Directory::GetParent( path );
         System::Console::WriteLine( directoryInfo->FullName );
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, or \HelloServer'                  contains invalid characters." );
      }

   }

   void Move( String^ sourcePath, String^ destinationPath )
   {
      try
      {
         System::IO::Directory::Move( sourcePath, destinationPath );
         System::Console::WriteLine(  "The directory move is complete." );
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, \HelloServer'                  or contains invalid characters." );
      }
      catch ( System::IO::IOException^ ) 
      {
         System::Console::WriteLine(  "An attempt was made to move a \HelloServer'                  directory to a different \HelloServer'                  volume, or destDirName \HelloServer'                  already exists." );
      }

   }

};

int main()
{
   Class1 * snippets = new Class1;
   String^ path = System::IO::Directory::GetCurrentDirectory();
   String^ filter =  "*.exe";
   snippets->PrintFileSystemEntries( path );
   snippets->PrintFileSystemEntries( path, filter );
   snippets->GetLogicalDrives();
   snippets->GetParent( path );
   snippets->Move(  "C:\\proof",  "C:\\Temp" );
   return 0;
}
using System;

namespace GetFileSystemEntries
{
    class Class1
    {
        static void Main(string[] args)
        {
            Class1 snippets = new Class1();

            string path = System.IO.Directory.GetCurrentDirectory();
            string filter = "*.exe";

            snippets.PrintFileSystemEntries(path);
            snippets.PrintFileSystemEntries(path, filter);		
            snippets.GetLogicalDrives();
            snippets.GetParent(path);
            snippets.Move("C:\\proof", "C:\\Temp");
        }

        void PrintFileSystemEntries(string path)
        {
            
            try
            {
                // Obtain the file system entries in the directory path.
                string[] directoryEntries =
                    System.IO.Directory.GetFileSystemEntries(path);

                foreach (string str in directoryEntries)
                {
                    System.Console.WriteLine(str);
                }
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, " +
                    "or contains invalid characters.");
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                System.Console.WriteLine("The path encapsulated in the " +
                    "Directory object does not exist.");
            }
        }
        void PrintFileSystemEntries(string path, string pattern)
        {
            try
            {
                // Obtain the file system entries in the directory
                // path that match the pattern.
                string[] directoryEntries =
                    System.IO.Directory.GetFileSystemEntries(path, pattern);

                foreach (string str in directoryEntries)
                {
                    System.Console.WriteLine(str);
                }
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, " +
                    "or contains invalid characters.");
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                System.Console.WriteLine("The path encapsulated in the " +
                    "Directory object does not exist.");
            }
        }

        // Print out all logical drives on the system.
        void GetLogicalDrives()
        {
            try
            {
                string[] drives = System.IO.Directory.GetLogicalDrives();

                foreach (string str in drives)
                {
                    System.Console.WriteLine(str);
                }
            }
            catch (System.IO.IOException)
            {
                System.Console.WriteLine("An I/O error occurs.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
        }
        void GetParent(string path)
        {
            try
            {
                System.IO.DirectoryInfo directoryInfo =
                    System.IO.Directory.GetParent(path);

                System.Console.WriteLine(directoryInfo.FullName);
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, or " +
                    "contains invalid characters.");
            }
        }
        void Move(string sourcePath, string destinationPath)
        {
            try
            {
                System.IO.Directory.Move(sourcePath, destinationPath);
                System.Console.WriteLine("The directory move is complete.");
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, " +
                    "or contains invalid characters.");	
            }
            catch (System.IO.IOException)
            {
                System.Console.WriteLine("An attempt was made to move a " +
                    "directory to a different " +
                    "volume, or destDirName " +
                    "already exists.");
            }
        }
    }
}
open System
open System.IO
open System.Security

let printFileSystemEntries path =
    try
        // Obtain the file system entries in the directory path.
        let directoryEntries = Directory.GetFileSystemEntries path

        for str in directoryEntries do
            printfn $"{str}"
    with 
    | :? ArgumentNullException ->
        printfn "Path is a null reference."
    | :? SecurityException ->
        printfn $"The caller does not have the required permission."
    | :? ArgumentException ->
        printfn $"Path is an empty string, contains only white spaces, or contains invalid characters."
    | :? DirectoryNotFoundException ->
        printfn $"The path encapsulated in the Directory object does not exist."

let printFileSystemEntriesPattern path pattern =
    try
        // Obtain the file system entries in the directory
        // path that match the pattern.
        let directoryEntries = Directory.GetFileSystemEntries(path, pattern)

        for str in directoryEntries do
            printfn $"{str}"
    with
    | :? ArgumentNullException -> printfn "Path is a null reference."
    | :? SecurityException -> printfn "The caller does not have the required permission."
    | :? ArgumentException -> printfn "Path is an empty string, contains only white spaces, or contains invalid characters."
    | :? DirectoryNotFoundException -> printfn "The path encapsulated in the Directory object does not exist."

// Print out all logical drives on the system.
let getLogicalDrives () =
    try
        let drives = Directory.GetLogicalDrives()

        for str in drives do
            printfn $"{str}"
    with
    | :? IOException -> printfn "An I/O error occurs."
    | :? SecurityException -> printfn "The caller does not have the required permission."

let getParent path =
    try
        let directoryInfo = Directory.GetParent path
        printfn $"{directoryInfo.FullName}"

    with
    | :? ArgumentNullException -> printfn "Path is a null reference."
    | :? ArgumentException -> printfn "Path is an empty string, contains only white spaces, or contains invalid characters."

let move sourcePath destinationPath =
    try
        Directory.Move(sourcePath, destinationPath)
        printfn "The directory move is complete."

    with
    | :? ArgumentNullException -> printfn "Path is a null reference."
    | :? SecurityException -> printfn "The caller does not have the required permission."
    | :? ArgumentException -> printfn "Path is an empty string, contains only white spaces, or contains invalid characters."
    | :? IOException -> printfn "An attempt was made to move a directory to a different volume, or destDirName already exists."

let path = Directory.GetCurrentDirectory()
let filter = "*.exe"

printFileSystemEntries path
printFileSystemEntriesPattern path filter
getLogicalDrives ()
getParent path
move "C:\\proof" "C:\\Temp"
Option Explicit On 
Option Strict On

Namespace GetFileSystemEntries
    Class Class1
        Overloads Shared Sub Main(ByVal args() As String)
            Dim snippets As New Class1()
            Dim path As String = System.IO.Directory.GetCurrentDirectory()
            Dim filter As String = "*.exe"
            snippets.PrintFileSystemEntries(path)
            snippets.PrintFileSystemEntries(path, filter)
            snippets.GetLogicalDrives()
            snippets.GetParent(path)
            snippets.Move("C:\proof", "C:\Temp")
        End Sub

        Sub PrintFileSystemEntries(ByVal path As String)
            Try
                ' Obtain the file system entries in the directory path.
                Dim directoryEntries As String()
                directoryEntries = System.IO.Directory.GetFileSystemEntries(path)
                Dim str As String
                For Each str In directoryEntries
                    System.Console.WriteLine(str)
                Next str
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                        "required permission.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                        "contains only white spaces, " + _
                                        "or contains invalid characters.")
            Catch exp As System.IO.DirectoryNotFoundException
                System.Console.WriteLine("The path encapsulated in the " + _
                                        "Directory object does not exist.")
            End Try
        End Sub
        Sub PrintFileSystemEntries(ByVal path As String, _
                                   ByVal pattern As String)
            Try
                ' Obtain the file system entries in the directory
                ' path that match the pattern.
                Dim directoryEntries As String()
                directoryEntries = _
                   System.IO.Directory.GetFileSystemEntries(path, pattern)

                Dim str As String
                For Each str In directoryEntries
                    System.Console.WriteLine(str)
                Next str
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                        "required permission.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                        "contains only white spaces, " + _
                                        "or contains invalid characters.")
            Catch exp As System.IO.DirectoryNotFoundException
                System.Console.WriteLine("The path encapsulated in the " + _
                                        "Directory object does not exist.")
            End Try
        End Sub

        ' Print out all logical drives on the system.
        Sub GetLogicalDrives()
            Try
                Dim drives As String()
                drives = System.IO.Directory.GetLogicalDrives()

                Dim str As String
                For Each str In drives
                    System.Console.WriteLine(str)
                Next str
            Catch exp As System.IO.IOException
                System.Console.WriteLine("An I/O error occurs.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                           "required permission.")
            End Try
        End Sub
        Sub GetParent(ByVal path As String)
            Try
                Dim directoryInfo As System.IO.DirectoryInfo
                directoryInfo = System.IO.Directory.GetParent(path)
                System.Console.WriteLine(directoryInfo.FullName)
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                     "contains only white spaces, or " + _
                                     "contains invalid characters.")
            End Try
        End Sub
        Sub Move(ByVal sourcePath As String, ByVal destinationPath As String)
            Try
                System.IO.Directory.Move(sourcePath, destinationPath)
                System.Console.WriteLine("The directory move is complete.")
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                           "required permission.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                        "contains only white spaces, " + _
                                        "or contains invalid characters.")
            Catch exp As System.IO.IOException
                System.Console.WriteLine("An attempt was made to move a " + _
                                        "directory to a different " + _
                                        "volume, or destDirName " + _
                                        "already exists.")
            End Try
        End Sub
    End Class
End Namespace

Uwagi

Kolejność zwracanych plików i nazw katalogów nie jest gwarantowana; Sort użyj metody , jeśli wymagana jest określona kolejność sortowania.

Metody EnumerateFileSystemEntries i GetFileSystemEntries różnią się w następujący sposób: w przypadku użycia EnumerateFileSystemEntriesmetody można rozpocząć wyliczanie kolekcji wpisów przed zwróceniem całej kolekcji. W przypadku użycia GetFileSystemEntriesmetody należy poczekać na zwrócenie całej tablicy wpisów, zanim będzie można uzyskać dostęp do tablicy. W związku z tym podczas pracy z wieloma plikami i katalogami EnumerateFileSystemEntries może być wydajniejszy.

Ta metoda jest identyczna GetFileSystemEntries z gwiazdką (*) określoną jako wzorzec wyszukiwania.

Parametr path może określać informacje o ścieżce względnej lub bezwzględnej. Informacje o ścieżce względnej są interpretowane jako względne w stosunku do bieżącego katalogu roboczego. Aby uzyskać bieżący katalog roboczy, zobacz GetCurrentDirectory.

Wielkość liter parametru path odpowiada wielkości liter w systemie plików, w którym jest uruchomiony kod. Na przykład jest rozróżniana wielkość liter w systemie plików NTFS (domyślny system plików systemu Windows) i rozróżniana jest wielkość liter w systemach plików systemu Linux.

Aby uzyskać listę typowych zadań we/wy, zobacz Typowe zadania we/wy.

Zobacz też

Dotyczy

GetFileSystemEntries(String, String)

Źródło:
Directory.cs
Źródło:
Directory.cs
Źródło:
Directory.cs

Zwraca tablicę nazw plików i nazw katalogów, które pasują do wzorca wyszukiwania w określonej ścieżce.

public:
 static cli::array <System::String ^> ^ GetFileSystemEntries(System::String ^ path, System::String ^ searchPattern);
public static string[] GetFileSystemEntries (string path, string searchPattern);
static member GetFileSystemEntries : string * string -> string[]
Public Shared Function GetFileSystemEntries (path As String, searchPattern As String) As String()

Parametry

path
String

Ścieżka względna lub bezwzględna do katalogu do wyszukania. W tym ciągu nie jest rozróżniana wielkość liter.

searchPattern
String

Ciąg wyszukiwania zgodny z nazwami plików i katalogów w pliku path. Ten parametr może zawierać kombinację prawidłowych znaków ścieżki literału i symboli wieloznacznych (* i ?), ale nie obsługuje wyrażeń regularnych.

Zwraca

String[]

Tablica nazw plików i nazw katalogów spełniających określone kryteria wyszukiwania lub pusta tablica, jeśli nie znaleziono plików lub katalogów.

Wyjątki

Obiekt wywołujący nie posiada wymaganych uprawnień.

.NET Framework i .NET Core w wersjach starszych niż 2.1: path jest ciągiem o zerowej długości, zawiera tylko biały znak lub zawiera co najmniej jeden nieprawidłowy znak. Możesz wykonać zapytanie o nieprawidłowe znaki za pomocą GetInvalidPathChars() metody .

-lub-

searchPattern nie zawiera prawidłowego wzorca.

path lub searchPattern ma wartość null.

Podana ścieżka, nazwa pliku lub obie przekraczają maksymalną długość zdefiniowaną przez system.

path to nazwa pliku.

Określona ścieżka jest nieprawidłowa (na przykład znajduje się na niezamapowanym dysku).

Przykłady

W poniższym przykładzie GetFileSystemEntries użyto metody , aby wypełnić tablicę ciągów nazwami wszystkich plików pasujących do filtru określonego przez użytkownika w określonej lokalizacji i wyświetla każdy ciąg w tablicy do konsoli. W tym przykładzie skonfigurowano przechwytywanie wszystkich błędów typowych dla tej metody.

using namespace System;
class Class1
{
public:
   void PrintFileSystemEntries( String^ path )
   {
      try
      {
         
         // Obtain the file system entries in the directory path.
         array<String^>^directoryEntries = System::IO::Directory::GetFileSystemEntries( path );
         for ( int i = 0; i < directoryEntries->Length; i++ )
         {
            System::Console::WriteLine( directoryEntries[ i ] );

         }
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, \HelloServer'                  or contains invalid characters." );
      }
      catch ( System::IO::DirectoryNotFoundException^ ) 
      {
         System::Console::WriteLine(  "The path encapsulated in the \HelloServer'                  Directory object does not exist." );
      }

   }

   void PrintFileSystemEntries( String^ path, String^ pattern )
   {
      try
      {
         
         // Obtain the file system entries in the directory
         // path that match the pattern.
         array<String^>^directoryEntries = System::IO::Directory::GetFileSystemEntries( path, pattern );
         for ( int i = 0; i < directoryEntries->Length; i++ )
         {
            System::Console::WriteLine( directoryEntries[ i ] );

         }
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, \HelloServer'                  or contains invalid characters." );
      }
      catch ( System::IO::DirectoryNotFoundException^ ) 
      {
         System::Console::WriteLine(  "The path encapsulated in the \HelloServer'                  Directory object does not exist." );
      }

   }


   // Print out all logical drives on the system.
   void GetLogicalDrives()
   {
      try
      {
         array<String^>^drives = System::IO::Directory::GetLogicalDrives();
         for ( int i = 0; i < drives->Length; i++ )
         {
            System::Console::WriteLine( drives[ i ] );

         }
      }
      catch ( System::IO::IOException^ ) 
      {
         System::Console::WriteLine(  "An I/O error occurs." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }

   }

   void GetParent( String^ path )
   {
      try
      {
         System::IO::DirectoryInfo^ directoryInfo = System::IO::Directory::GetParent( path );
         System::Console::WriteLine( directoryInfo->FullName );
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, or \HelloServer'                  contains invalid characters." );
      }

   }

   void Move( String^ sourcePath, String^ destinationPath )
   {
      try
      {
         System::IO::Directory::Move( sourcePath, destinationPath );
         System::Console::WriteLine(  "The directory move is complete." );
      }
      catch ( ArgumentNullException^ ) 
      {
         System::Console::WriteLine(  "Path is a null reference." );
      }
      catch ( System::Security::SecurityException^ ) 
      {
         System::Console::WriteLine(  "The caller does not have the \HelloServer'                  required permission." );
      }
      catch ( ArgumentException^ ) 
      {
         System::Console::WriteLine(  "Path is an empty String, \HelloServer'                  contains only white spaces, \HelloServer'                  or contains invalid characters." );
      }
      catch ( System::IO::IOException^ ) 
      {
         System::Console::WriteLine(  "An attempt was made to move a \HelloServer'                  directory to a different \HelloServer'                  volume, or destDirName \HelloServer'                  already exists." );
      }

   }

};

int main()
{
   Class1 * snippets = new Class1;
   String^ path = System::IO::Directory::GetCurrentDirectory();
   String^ filter =  "*.exe";
   snippets->PrintFileSystemEntries( path );
   snippets->PrintFileSystemEntries( path, filter );
   snippets->GetLogicalDrives();
   snippets->GetParent( path );
   snippets->Move(  "C:\\proof",  "C:\\Temp" );
   return 0;
}
using System;

namespace GetFileSystemEntries
{
    class Class1
    {
        static void Main(string[] args)
        {
            Class1 snippets = new Class1();

            string path = System.IO.Directory.GetCurrentDirectory();
            string filter = "*.exe";

            snippets.PrintFileSystemEntries(path);
            snippets.PrintFileSystemEntries(path, filter);		
            snippets.GetLogicalDrives();
            snippets.GetParent(path);
            snippets.Move("C:\\proof", "C:\\Temp");
        }

        void PrintFileSystemEntries(string path)
        {
            
            try
            {
                // Obtain the file system entries in the directory path.
                string[] directoryEntries =
                    System.IO.Directory.GetFileSystemEntries(path);

                foreach (string str in directoryEntries)
                {
                    System.Console.WriteLine(str);
                }
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, " +
                    "or contains invalid characters.");
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                System.Console.WriteLine("The path encapsulated in the " +
                    "Directory object does not exist.");
            }
        }
        void PrintFileSystemEntries(string path, string pattern)
        {
            try
            {
                // Obtain the file system entries in the directory
                // path that match the pattern.
                string[] directoryEntries =
                    System.IO.Directory.GetFileSystemEntries(path, pattern);

                foreach (string str in directoryEntries)
                {
                    System.Console.WriteLine(str);
                }
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, " +
                    "or contains invalid characters.");
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                System.Console.WriteLine("The path encapsulated in the " +
                    "Directory object does not exist.");
            }
        }

        // Print out all logical drives on the system.
        void GetLogicalDrives()
        {
            try
            {
                string[] drives = System.IO.Directory.GetLogicalDrives();

                foreach (string str in drives)
                {
                    System.Console.WriteLine(str);
                }
            }
            catch (System.IO.IOException)
            {
                System.Console.WriteLine("An I/O error occurs.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
        }
        void GetParent(string path)
        {
            try
            {
                System.IO.DirectoryInfo directoryInfo =
                    System.IO.Directory.GetParent(path);

                System.Console.WriteLine(directoryInfo.FullName);
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, or " +
                    "contains invalid characters.");
            }
        }
        void Move(string sourcePath, string destinationPath)
        {
            try
            {
                System.IO.Directory.Move(sourcePath, destinationPath);
                System.Console.WriteLine("The directory move is complete.");
            }
            catch (ArgumentNullException)
            {
                System.Console.WriteLine("Path is a null reference.");
            }
            catch (System.Security.SecurityException)
            {
                System.Console.WriteLine("The caller does not have the " +
                    "required permission.");
            }
            catch (ArgumentException)
            {
                System.Console.WriteLine("Path is an empty string, " +
                    "contains only white spaces, " +
                    "or contains invalid characters.");	
            }
            catch (System.IO.IOException)
            {
                System.Console.WriteLine("An attempt was made to move a " +
                    "directory to a different " +
                    "volume, or destDirName " +
                    "already exists.");
            }
        }
    }
}
open System
open System.IO
open System.Security

let printFileSystemEntries path =
    try
        // Obtain the file system entries in the directory path.
        let directoryEntries = Directory.GetFileSystemEntries path

        for str in directoryEntries do
            printfn $"{str}"
    with 
    | :? ArgumentNullException ->
        printfn "Path is a null reference."
    | :? SecurityException ->
        printfn $"The caller does not have the required permission."
    | :? ArgumentException ->
        printfn $"Path is an empty string, contains only white spaces, or contains invalid characters."
    | :? DirectoryNotFoundException ->
        printfn $"The path encapsulated in the Directory object does not exist."

let printFileSystemEntriesPattern path pattern =
    try
        // Obtain the file system entries in the directory
        // path that match the pattern.
        let directoryEntries = Directory.GetFileSystemEntries(path, pattern)

        for str in directoryEntries do
            printfn $"{str}"
    with
    | :? ArgumentNullException -> printfn "Path is a null reference."
    | :? SecurityException -> printfn "The caller does not have the required permission."
    | :? ArgumentException -> printfn "Path is an empty string, contains only white spaces, or contains invalid characters."
    | :? DirectoryNotFoundException -> printfn "The path encapsulated in the Directory object does not exist."

// Print out all logical drives on the system.
let getLogicalDrives () =
    try
        let drives = Directory.GetLogicalDrives()

        for str in drives do
            printfn $"{str}"
    with
    | :? IOException -> printfn "An I/O error occurs."
    | :? SecurityException -> printfn "The caller does not have the required permission."

let getParent path =
    try
        let directoryInfo = Directory.GetParent path
        printfn $"{directoryInfo.FullName}"

    with
    | :? ArgumentNullException -> printfn "Path is a null reference."
    | :? ArgumentException -> printfn "Path is an empty string, contains only white spaces, or contains invalid characters."

let move sourcePath destinationPath =
    try
        Directory.Move(sourcePath, destinationPath)
        printfn "The directory move is complete."

    with
    | :? ArgumentNullException -> printfn "Path is a null reference."
    | :? SecurityException -> printfn "The caller does not have the required permission."
    | :? ArgumentException -> printfn "Path is an empty string, contains only white spaces, or contains invalid characters."
    | :? IOException -> printfn "An attempt was made to move a directory to a different volume, or destDirName already exists."

let path = Directory.GetCurrentDirectory()
let filter = "*.exe"

printFileSystemEntries path
printFileSystemEntriesPattern path filter
getLogicalDrives ()
getParent path
move "C:\\proof" "C:\\Temp"
Option Explicit On 
Option Strict On

Namespace GetFileSystemEntries
    Class Class1
        Overloads Shared Sub Main(ByVal args() As String)
            Dim snippets As New Class1()
            Dim path As String = System.IO.Directory.GetCurrentDirectory()
            Dim filter As String = "*.exe"
            snippets.PrintFileSystemEntries(path)
            snippets.PrintFileSystemEntries(path, filter)
            snippets.GetLogicalDrives()
            snippets.GetParent(path)
            snippets.Move("C:\proof", "C:\Temp")
        End Sub

        Sub PrintFileSystemEntries(ByVal path As String)
            Try
                ' Obtain the file system entries in the directory path.
                Dim directoryEntries As String()
                directoryEntries = System.IO.Directory.GetFileSystemEntries(path)
                Dim str As String
                For Each str In directoryEntries
                    System.Console.WriteLine(str)
                Next str
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                        "required permission.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                        "contains only white spaces, " + _
                                        "or contains invalid characters.")
            Catch exp As System.IO.DirectoryNotFoundException
                System.Console.WriteLine("The path encapsulated in the " + _
                                        "Directory object does not exist.")
            End Try
        End Sub
        Sub PrintFileSystemEntries(ByVal path As String, _
                                   ByVal pattern As String)
            Try
                ' Obtain the file system entries in the directory
                ' path that match the pattern.
                Dim directoryEntries As String()
                directoryEntries = _
                   System.IO.Directory.GetFileSystemEntries(path, pattern)

                Dim str As String
                For Each str In directoryEntries
                    System.Console.WriteLine(str)
                Next str
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                        "required permission.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                        "contains only white spaces, " + _
                                        "or contains invalid characters.")
            Catch exp As System.IO.DirectoryNotFoundException
                System.Console.WriteLine("The path encapsulated in the " + _
                                        "Directory object does not exist.")
            End Try
        End Sub

        ' Print out all logical drives on the system.
        Sub GetLogicalDrives()
            Try
                Dim drives As String()
                drives = System.IO.Directory.GetLogicalDrives()

                Dim str As String
                For Each str In drives
                    System.Console.WriteLine(str)
                Next str
            Catch exp As System.IO.IOException
                System.Console.WriteLine("An I/O error occurs.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                           "required permission.")
            End Try
        End Sub
        Sub GetParent(ByVal path As String)
            Try
                Dim directoryInfo As System.IO.DirectoryInfo
                directoryInfo = System.IO.Directory.GetParent(path)
                System.Console.WriteLine(directoryInfo.FullName)
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                     "contains only white spaces, or " + _
                                     "contains invalid characters.")
            End Try
        End Sub
        Sub Move(ByVal sourcePath As String, ByVal destinationPath As String)
            Try
                System.IO.Directory.Move(sourcePath, destinationPath)
                System.Console.WriteLine("The directory move is complete.")
            Catch exp As ArgumentNullException
                System.Console.WriteLine("Path is a null reference.")
            Catch exp As System.Security.SecurityException
                System.Console.WriteLine("The caller does not have the " + _
                                           "required permission.")
            Catch exp As ArgumentException
                System.Console.WriteLine("Path is an empty string, " + _
                                        "contains only white spaces, " + _
                                        "or contains invalid characters.")
            Catch exp As System.IO.IOException
                System.Console.WriteLine("An attempt was made to move a " + _
                                        "directory to a different " + _
                                        "volume, or destDirName " + _
                                        "already exists.")
            End Try
        End Sub
    End Class
End Namespace

Uwagi

Kolejność zwracanych plików i nazw katalogów nie jest gwarantowana; Sort użyj metody , jeśli wymagana jest określona kolejność sortowania.

searchPattern może być kombinacją literałów i symboli wieloznacznych, ale nie obsługuje wyrażeń regularnych. Następujące specyfikatory symboli wieloznacznych są dozwolone w programie searchPattern.

Specyfikator symboli wieloznacznych Jest zgodny z
* (gwiazdka) Zero lub więcej znaków w tej pozycji.
? (znak zapytania) Dokładnie jeden znak w tej pozycji.

Znaki inne niż symbol wieloznaczny to znaki literału. Na przykład searchPattern ciąg "*t" wyszukuje wszystkie nazwy path kończące się literą "t". Ciąg searchPattern "s*" wyszukuje wszystkie nazwy, path zaczynając od litery "s".

searchPattern program nie może kończyć się dwoma kropkami ("..") ani zawierać dwóch kropek (".."), po których następuje DirectorySeparatorChar znak lub AltDirectorySeparatorChar, ani nie może zawierać żadnych nieprawidłowych znaków. Zapytania dotyczące nieprawidłowych znaków można wykonać przy użyciu GetInvalidPathChars metody .

Uwaga

W przypadku używania znaku wieloznakowego gwiazdki w obiekcie searchPattern takim jak "*.txt" liczba znaków w określonym rozszerzeniu wpływa na wyszukiwanie w następujący sposób:

  • Jeśli określone rozszerzenie ma dokładnie trzy znaki długości, metoda zwraca pliki z rozszerzeniami rozpoczynającymi się od określonego rozszerzenia. Na przykład wyrażenie "*.xls" zwraca zarówno "book.xls", jak i "book.xlsx".
  • We wszystkich innych przypadkach metoda zwraca pliki, które dokładnie pasują do określonego rozszerzenia. Na przykład wyrażenie "*.ai" zwraca wartość "file.ai", ale nie "file.aif".

Jeśli używasz symbolu wieloznakowego znaku zapytania, ta metoda zwraca tylko pliki zgodne z określonym rozszerzeniem pliku. Na przykład w przypadku dwóch plików "file1.txt" i "file1.txtother" w katalogu wzorzec wyszukiwania "file?.txt" zwraca tylko pierwszy plik, podczas gdy wzorzec wyszukiwania "file*.txt" zwraca oba pliki.

Parametr path może określać informacje o ścieżce względnej lub bezwzględnej. Informacje o ścieżce względnej są interpretowane jako względne w stosunku do bieżącego katalogu roboczego. Aby uzyskać bieżący katalog roboczy, zobacz GetCurrentDirectory.

Wielkość liter parametru path odpowiada wielkości liter w systemie plików, w którym jest uruchomiony kod. Na przykład jest rozróżniana wielkość liter w systemie plików NTFS (domyślny system plików systemu Windows) i rozróżniana jest wielkość liter w systemach plików systemu Linux.

Aby uzyskać listę typowych zadań we/wy, zobacz Typowe zadania we/wy.

Zobacz też

Dotyczy

GetFileSystemEntries(String, String, EnumerationOptions)

Źródło:
Directory.cs
Źródło:
Directory.cs
Źródło:
Directory.cs

Zwraca tablicę nazw plików i nazw katalogów, które pasują do wzorca wyszukiwania i opcji wyliczenia w określonej ścieżce.

public:
 static cli::array <System::String ^> ^ GetFileSystemEntries(System::String ^ path, System::String ^ searchPattern, System::IO::EnumerationOptions ^ enumerationOptions);
public static string[] GetFileSystemEntries (string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions);
static member GetFileSystemEntries : string * string * System.IO.EnumerationOptions -> string[]
Public Shared Function GetFileSystemEntries (path As String, searchPattern As String, enumerationOptions As EnumerationOptions) As String()

Parametry

path
String

Ścieżka względna lub bezwzględna do katalogu do wyszukania. W tym ciągu nie jest rozróżniana wielkość liter.

searchPattern
String

Ciąg wyszukiwania zgodny z nazwami podkatalogów w pliku path. Ten parametr może zawierać kombinację prawidłowych literałów i symboli wieloznacznych, ale nie obsługuje wyrażeń regularnych.

enumerationOptions
EnumerationOptions

Obiekt opisujący konfigurację wyszukiwania i wyliczenia do użycia.

Zwraca

String[]

Tablica nazw plików i nazw katalogów pasujących do określonego wzorca wyszukiwania i opcji wyliczania lub pusta tablica, jeśli nie znaleziono plików lub katalogów.

Wyjątki

Obiekt wywołujący nie posiada wymaganych uprawnień.

.NET Framework i .NET Core w wersjach starszych niż 2.1: path jest ciągiem o zerowej długości, zawiera tylko biały znak lub zawiera co najmniej jeden nieprawidłowy znak. Możesz wykonać zapytanie o nieprawidłowe znaki za pomocą GetInvalidPathChars() metody .

-lub-

searchPattern nie zawiera prawidłowego wzorca.

path lub searchPattern ma wartość null.

Podana ścieżka, nazwa pliku lub obie przekraczają maksymalną długość zdefiniowaną przez system.

path to nazwa pliku.

Określona ścieżka jest nieprawidłowa (na przykład znajduje się na niezamapowanym dysku).

Uwagi

Kolejność zwracanych plików i nazw katalogów nie jest gwarantowana; Sort użyj metody , jeśli wymagana jest określona kolejność sortowania.

searchPattern może być kombinacją literałów i symboli wieloznacznych, ale nie obsługuje wyrażeń regularnych. Następujące specyfikatory symboli wieloznacznych są dozwolone w programie searchPattern.

Specyfikator symboli wieloznacznych Jest zgodny z
* (gwiazdka) Zero lub więcej znaków w tej pozycji.
? (znak zapytania) Dokładnie jeden znak w tej pozycji.

Znaki inne niż symbol wieloznaczny to znaki literału. Na przykład searchPattern ciąg "*t" wyszukuje wszystkie nazwy path kończące się literą "t". Ciąg searchPattern "s*" wyszukuje wszystkie nazwy, path zaczynając od litery "s".

searchPattern program nie może kończyć się dwoma kropkami ("..") ani zawierać dwóch kropek (".."), po których następuje DirectorySeparatorChar znak lub AltDirectorySeparatorChar, ani nie może zawierać żadnych nieprawidłowych znaków. Zapytania dotyczące nieprawidłowych znaków można wykonać przy użyciu GetInvalidPathChars metody .

Uwaga

W przypadku używania znaku wieloznakowego gwiazdki w obiekcie searchPattern takim jak "*.txt" liczba znaków w określonym rozszerzeniu wpływa na wyszukiwanie w następujący sposób:

  • Jeśli określone rozszerzenie ma dokładnie trzy znaki długości, metoda zwraca pliki z rozszerzeniami rozpoczynającymi się od określonego rozszerzenia. Na przykład wyrażenie "*.xls" zwraca zarówno "book.xls", jak i "book.xlsx".
  • We wszystkich innych przypadkach metoda zwraca pliki, które dokładnie pasują do określonego rozszerzenia. Na przykład wyrażenie "*.ai" zwraca wartość "file.ai", ale nie "file.aif".

Jeśli używasz symbolu wieloznakowego znaku zapytania, ta metoda zwraca tylko pliki zgodne z określonym rozszerzeniem pliku. Na przykład w przypadku dwóch plików "file1.txt" i "file1.txtother" w katalogu wzorzec wyszukiwania "file?.txt" zwraca tylko pierwszy plik, podczas gdy wzorzec wyszukiwania "file*.txt" zwraca oba pliki.

Parametr path może określać informacje o ścieżce względnej lub bezwzględnej. Informacje o ścieżce względnej są interpretowane jako względne w stosunku do bieżącego katalogu roboczego. Aby uzyskać bieżący katalog roboczy, zobacz GetCurrentDirectory.

Wielkość liter parametru path odpowiada wielkości liter w systemie plików, w którym jest uruchomiony kod. Na przykład jest rozróżniana wielkość liter w systemie plików NTFS (domyślny system plików systemu Windows) i rozróżniana jest wielkość liter w systemach plików systemu Linux.

Aby uzyskać listę typowych zadań we/wy, zobacz Typowe zadania we/wy.

Dotyczy

GetFileSystemEntries(String, String, SearchOption)

Źródło:
Directory.cs
Źródło:
Directory.cs
Źródło:
Directory.cs

Zwraca tablicę wszystkich nazw plików i nazw katalogów pasujących do wzorca wyszukiwania w określonej ścieżce i opcjonalnie wyszukuje podkatalogi.

public:
 static cli::array <System::String ^> ^ GetFileSystemEntries(System::String ^ path, System::String ^ searchPattern, System::IO::SearchOption searchOption);
public static string[] GetFileSystemEntries (string path, string searchPattern, System.IO.SearchOption searchOption);
static member GetFileSystemEntries : string * string * System.IO.SearchOption -> string[]
Public Shared Function GetFileSystemEntries (path As String, searchPattern As String, searchOption As SearchOption) As String()

Parametry

path
String

Ścieżka względna lub bezwzględna do katalogu do wyszukania. W tym ciągu nie jest rozróżniana wielkość liter.

searchPattern
String

Ciąg wyszukiwania zgodny z nazwami plików i katalogów w pliku path. Ten parametr może zawierać kombinację prawidłowych znaków ścieżki literału i symboli wieloznacznych (* i ?), ale nie obsługuje wyrażeń regularnych.

searchOption
SearchOption

Jedna z wartości wyliczenia określająca, czy operacja wyszukiwania powinna zawierać tylko bieżący katalog, czy powinna zawierać wszystkie podkatalogi. Wartość domyślna to TopDirectoryOnly.

Zwraca

String[]

Tablica plików nazw plików i nazw katalogów spełniających określone kryteria wyszukiwania lub pusta tablica, jeśli nie znaleziono plików lub katalogów.

Wyjątki

.NET Framework i .NET Core w wersjach starszych niż 2.1: path jest ciągiem o zerowej długości, zawiera tylko białe znaki lub zawiera nieprawidłowe znaki. Zapytania dotyczące nieprawidłowych znaków można wykonać przy użyciu GetInvalidPathChars() metody .

-lub-

searchPattern nie zawiera prawidłowego wzorca.

path to null.

-lub-

searchPattern to null.

searchOption jest nieprawidłową SearchOption wartością.

path jest nieprawidłowy, na przykład odwołując się do niezamapowanego dysku.

path to nazwa pliku.

Określona ścieżka, nazwa pliku lub łączna długość przekracza zdefiniowaną przez system maksymalną długość.

Obiekt wywołujący nie posiada wymaganych uprawnień.

Obiekt wywołujący nie posiada wymaganych uprawnień.

Uwagi

Kolejność zwracanych plików i nazw katalogów nie jest gwarantowana; Sort użyj metody , jeśli wymagana jest określona kolejność sortowania.

searchPattern może być kombinacją literałów i symboli wieloznacznych, ale nie obsługuje wyrażeń regularnych. Następujące specyfikatory symboli wieloznacznych są dozwolone w programie searchPattern.

Specyfikator symboli wieloznacznych Jest zgodny z
* (gwiazdka) Zero lub więcej znaków w tej pozycji.
? (znak zapytania) Dokładnie jeden znak w tej pozycji.

Znaki inne niż symbol wieloznaczny to znaki literału. Na przykład searchPattern ciąg "*t" wyszukuje wszystkie nazwy path kończące się literą "t". Ciąg searchPattern "s*" wyszukuje wszystkie nazwy, path zaczynając od litery "s".

searchPattern program nie może kończyć się dwoma kropkami ("..") ani zawierać dwóch kropek (".."), po których następuje DirectorySeparatorChar znak lub AltDirectorySeparatorChar, ani nie może zawierać żadnych nieprawidłowych znaków. Zapytania dotyczące nieprawidłowych znaków można wykonać przy użyciu GetInvalidPathChars metody .

Uwaga

W przypadku używania znaku wieloznakowego gwiazdki w obiekcie searchPattern takim jak "*.txt" liczba znaków w określonym rozszerzeniu wpływa na wyszukiwanie w następujący sposób:

  • Jeśli określone rozszerzenie ma dokładnie trzy znaki długości, metoda zwraca pliki z rozszerzeniami rozpoczynającymi się od określonego rozszerzenia. Na przykład wyrażenie "*.xls" zwraca zarówno "book.xls", jak i "book.xlsx".
  • We wszystkich innych przypadkach metoda zwraca pliki, które dokładnie pasują do określonego rozszerzenia. Na przykład wyrażenie "*.ai" zwraca wartość "file.ai", ale nie "file.aif".

Jeśli używasz symbolu wieloznakowego znaku zapytania, ta metoda zwraca tylko pliki zgodne z określonym rozszerzeniem pliku. Na przykład w przypadku dwóch plików "file1.txt" i "file1.txtother" w katalogu wzorzec wyszukiwania "file?.txt" zwraca tylko pierwszy plik, podczas gdy wzorzec wyszukiwania "file*.txt" zwraca oba pliki.

Metody EnumerateFileSystemEntries i GetFileSystemEntries różnią się w następujący sposób: w przypadku użycia EnumerateFileSystemEntriesmetody można rozpocząć wyliczanie kolekcji wpisów przed zwróceniem całej kolekcji. W przypadku użycia GetFileSystemEntriesmetody należy poczekać na zwrócenie całej tablicy wpisów, zanim będzie można uzyskać dostęp do tablicy. W związku z tym podczas pracy z wieloma plikami i katalogami EnumerateFileSystemEntries może być wydajniejszy.

Możesz określić informacje o ścieżce względnej za pomocą parametru path . Informacje o ścieżce względnej są interpretowane jako względem bieżącego katalogu roboczego, który można określić przy użyciu GetCurrentDirectory metody .

Zobacz też

Dotyczy