Directory.GetFileSystemEntries 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 조건을 충족하는 모든 파일 및 하위 디렉터리의 이름을 반환합니다.
오버로드
| Name | Description |
|---|---|
| GetFileSystemEntries(String) |
지정된 경로에 있는 모든 파일 및 하위 디렉터리의 이름을 반환합니다. |
| GetFileSystemEntries(String, String) |
지정된 경로의 검색 패턴과 일치하는 파일 이름 및 디렉터리 이름의 배열을 반환합니다. |
| GetFileSystemEntries(String, String, EnumerationOptions) |
지정된 경로의 검색 패턴 및 열거 옵션과 일치하는 파일 이름 및 디렉터리 이름의 배열을 반환합니다. |
| GetFileSystemEntries(String, String, SearchOption) |
지정된 경로의 검색 패턴과 일치하는 모든 파일 이름 및 디렉터리 이름의 배열을 반환하고 선택적으로 하위 디렉터리를 검색합니다. |
GetFileSystemEntries(String)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
지정된 경로에 있는 모든 파일 및 하위 디렉터리의 이름을 반환합니다.
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()
매개 변수
- path
- String
검색할 디렉터리의 상대 또는 절대 경로입니다. 이 문자열은 대/소문자를 구분하지 않습니다.
반품
지정된 디렉터리에 있는 파일 및 하위 디렉터리의 이름 배열이거나 파일 또는 하위 디렉터리가 없는 경우 빈 배열입니다.
예외
호출자에게 필요한 권한이 없습니다.
.NET Framework 및 .NET Core 버전 2.1 이전: path 길이가 0인 문자열이거나, 공백만 포함하거나, 하나 이상의 잘못된 문자를 포함합니다. 를 사용하여 잘못된 문자를 GetInvalidPathChars()쿼리할 수 있습니다.
path은 null입니다.
지정된 경로, 파일 이름 또는 둘 다 시스템 정의 최대 길이를 초과합니다.
path 은 파일 이름입니다.
지정한 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있는 경우).
예제
다음 예제에서는 메서드를 사용하여 GetFileSystemEntries 사용자가 지정한 위치에 있는 모든 파일 및 하위 디렉터리의 이름으로 문자열 배열을 채우고 배열의 각 문자열을 콘솔에 출력합니다. 이 예제는 이 메서드에 공통된 모든 오류를 catch하도록 구성됩니다.
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
설명
반환된 파일 및 디렉터리 이름의 순서는 보장되지 않습니다. 특정 정렬 순서가 Sort 필요한 경우 메서드를 사용합니다.
메서드 및 EnumerateFileSystemEntries 메서드는 GetFileSystemEntries 다음과 같이 다릅니다. 사용할 EnumerateFileSystemEntries때 전체 컬렉션이 반환되기 전에 항목 컬렉션을 열거할 수 있습니다. 사용할 GetFileSystemEntries경우 배열에 액세스하기 전에 전체 항목 배열이 반환될 때까지 기다려야 합니다. 따라서 많은 파일 및 디렉터리 EnumerateFileSystemEntries 로 작업하는 경우 더 효율적일 수 있습니다.
이 메서드는 검색 패턴으로 지정된 별표(*)와 동일합니다 GetFileSystemEntries .
path 매개 변수는 상대 또는 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리를 기준으로 해석됩니다. 현재 작업 디렉터리를 가져오려면 다음을 참조하세요 GetCurrentDirectory.
매개 변수의 path 대/소문자 구분은 코드가 실행 중인 파일 시스템의 대/소문자 구분에 해당합니다. 예를 들어 NTFS(기본 Windows 파일 시스템)에서는 대/소문자를 구분하지 않으며 Linux 파일 시스템에서는 대/소문자를 구분합니다.
일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.
추가 정보
적용 대상
GetFileSystemEntries(String, String)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
지정된 경로의 검색 패턴과 일치하는 파일 이름 및 디렉터리 이름의 배열을 반환합니다.
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()
매개 변수
- path
- String
검색할 디렉터리의 상대 또는 절대 경로입니다. 이 문자열은 대/소문자를 구분하지 않습니다.
- searchPattern
- String
에서 파일 및 디렉터리 이름과 일치시킬 검색 문자열입니다 path. 이 매개 변수는 유효한 리터럴 경로와 와일드카드(* 및 ?) 문자의 조합을 포함할 수 있지만 정규식을 지원하지는 않습니다.
반품
지정된 검색 조건과 일치하는 파일 이름 및 디렉터리 이름의 배열이거나 파일 또는 디렉터리를 찾을 수 없는 경우 빈 배열입니다.
예외
호출자에게 필요한 권한이 없습니다.
.NET Framework 및 .NET Core 버전 2.1 이전: path 길이가 0인 문자열이거나, 공백만 포함하거나, 하나 이상의 잘못된 문자를 포함합니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars() 수 있습니다.
-또는-
searchPattern 은 유효한 패턴을 포함하지 않습니다.
path 또는 searchPattern .입니다 null.
지정된 경로, 파일 이름 또는 둘 다 시스템 정의 최대 길이를 초과합니다.
path 은 파일 이름입니다.
지정한 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있는 경우).
예제
다음 예제에서는 메서드를 GetFileSystemEntries 사용하여 특정 위치에서 사용자가 지정한 필터와 일치하는 모든 파일의 이름으로 문자열 배열을 채우고 배열의 각 문자열을 콘솔에 출력합니다. 이 예제는 이 메서드에 공통된 모든 오류를 catch하도록 구성됩니다.
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
설명
반환된 파일 및 디렉터리 이름의 순서는 보장되지 않습니다. 특정 정렬 순서가 Sort 필요한 경우 메서드를 사용합니다.
searchPattern 는 리터럴과 와일드카드 문자의 조합일 수 있지만 정규식을 지원하지는 않습니다. 다음 와일드카드 지정자는 .에서 searchPattern허용됩니다.
| 와일드카드 지정자 | 검색 결과 |
|---|---|
| * (별표) | 해당 위치에 있는 문자가 0개 이상입니다. |
| ? (물음표) | 정확히 그 위치에 있는 한 문자입니다. |
와일드카드 이외의 문자는 리터럴 문자입니다. 예를 들어 searchPattern 문자열 "*t"는 문자 "t"로 끝나는 모든 이름을 path 검색합니다. 문자열 "s*"는 searchPattern 문자 "s"로 path 시작하는 모든 이름을 검색합니다.
searchPattern 는 두 개의 마침표("..")로 끝나거나 두 개의 마침표("..") DirectorySeparatorChar 를 포함하거나 AltDirectorySeparatorChar잘못된 문자를 포함할 수 없습니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars 수 있습니다.
메모
"*.txt"와 같은 별표 와일드카드 문자를 searchPattern 사용하면 지정된 확장의 문자 수가 다음과 같이 검색에 영향을 줍니다.
- 지정된 확장의 길이가 정확히 3자인 경우 메서드는 지정된 확장명으로 시작하는 확장명을 가진 파일을 반환합니다. 예를 들어 "*.xls"는 "book.xls" 및 "book.xlsx"를 모두 반환합니다.
- 다른 모든 경우에서 메서드는 지정된 확장과 정확히 일치하는 파일을 반환합니다. 예를 들어 "*.ai"는 "file.ai"를 반환하지만 "file.aif"는 반환하지 않습니다.
물음표 와일드카드 문자를 사용하는 경우 이 메서드는 지정된 파일 확장과 일치하는 파일만 반환합니다. 예를 들어 디렉터리에서 "file1.txt" 및 "file1.txtother"라는 두 개의 파일이 "file?.txt"는 첫 번째 파일만 반환하지만 "file*.txt"의 검색 패턴은 두 파일을 모두 반환합니다.
path 매개 변수는 상대 또는 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리를 기준으로 해석됩니다. 현재 작업 디렉터리를 가져오려면 다음을 참조하세요 GetCurrentDirectory.
매개 변수의 path 대/소문자 구분은 코드가 실행 중인 파일 시스템의 대/소문자 구분에 해당합니다. 예를 들어 NTFS(기본 Windows 파일 시스템)에서는 대/소문자를 구분하지 않으며 Linux 파일 시스템에서는 대/소문자를 구분합니다.
일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.
추가 정보
적용 대상
GetFileSystemEntries(String, String, EnumerationOptions)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
지정된 경로의 검색 패턴 및 열거 옵션과 일치하는 파일 이름 및 디렉터리 이름의 배열을 반환합니다.
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()
매개 변수
- path
- String
검색할 디렉터리의 상대 또는 절대 경로입니다. 이 문자열은 대/소문자를 구분하지 않습니다.
- searchPattern
- String
에서 파일 및 디렉터리 이름과 일치시킬 검색 문자열입니다 path. 이 매개 변수는 유효한 리터럴과 와일드카드 문자의 조합을 포함할 수 있지만 정규식을 지원하지는 않습니다.
- enumerationOptions
- EnumerationOptions
사용할 검색 및 열거형 구성을 설명하는 개체입니다.
반품
지정된 검색 패턴 및 열거형 옵션과 일치하는 파일 이름 및 디렉터리 이름의 배열이거나 파일 또는 디렉터리를 찾을 수 없는 경우 빈 배열입니다.
예외
호출자에게 필요한 권한이 없습니다.
.NET Framework 및 .NET Core 버전 2.1 이전: path 길이가 0인 문자열이거나, 공백만 포함하거나, 하나 이상의 잘못된 문자를 포함합니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars() 수 있습니다.
-또는-
searchPattern 은 유효한 패턴을 포함하지 않습니다.
path 또는 searchPattern .입니다 null.
지정된 경로, 파일 이름 또는 둘 다 시스템 정의 최대 길이를 초과합니다.
path 은 파일 이름입니다.
지정한 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있는 경우).
설명
반환된 파일 및 디렉터리 이름의 순서는 보장되지 않습니다. 특정 정렬 순서가 Sort 필요한 경우 메서드를 사용합니다.
searchPattern 는 리터럴과 와일드카드 문자의 조합일 수 있지만 정규식을 지원하지는 않습니다. 다음 와일드카드 지정자는 .에서 searchPattern허용됩니다.
| 와일드카드 지정자 | 검색 결과 |
|---|---|
| * (별표) | 해당 위치에 있는 문자가 0개 이상입니다. |
| ? (물음표) | 정확히 그 위치에 있는 한 문자입니다. |
와일드카드 이외의 문자는 리터럴 문자입니다. 예를 들어 searchPattern 문자열 "*t"는 문자 "t"로 끝나는 모든 이름을 path 검색합니다. 문자열 "s*"는 searchPattern 문자 "s"로 path 시작하는 모든 이름을 검색합니다.
searchPattern 는 두 개의 마침표("..")로 끝나거나 두 개의 마침표("..") DirectorySeparatorChar 를 포함하거나 AltDirectorySeparatorChar잘못된 문자를 포함할 수 없습니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars 수 있습니다.
메모
"*.txt"와 같은 별표 와일드카드 문자를 searchPattern 사용하면 지정된 확장의 문자 수가 다음과 같이 검색에 영향을 줍니다.
- 지정된 확장의 길이가 정확히 3자인 경우 메서드는 지정된 확장명으로 시작하는 확장명을 가진 파일을 반환합니다. 예를 들어 "*.xls"는 "book.xls" 및 "book.xlsx"를 모두 반환합니다.
- 다른 모든 경우에서 메서드는 지정된 확장과 정확히 일치하는 파일을 반환합니다. 예를 들어 "*.ai"는 "file.ai"를 반환하지만 "file.aif"는 반환하지 않습니다.
물음표 와일드카드 문자를 사용하는 경우 이 메서드는 지정된 파일 확장과 일치하는 파일만 반환합니다. 예를 들어 디렉터리에서 "file1.txt" 및 "file1.txtother"라는 두 개의 파일이 "file?.txt"는 첫 번째 파일만 반환하지만 "file*.txt"의 검색 패턴은 두 파일을 모두 반환합니다.
path 매개 변수는 상대 또는 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리를 기준으로 해석됩니다. 현재 작업 디렉터리를 가져오려면 다음을 참조하세요 GetCurrentDirectory.
매개 변수의 path 대/소문자 구분은 코드가 실행 중인 파일 시스템의 대/소문자 구분에 해당합니다. 예를 들어 NTFS(기본 Windows 파일 시스템)에서는 대/소문자를 구분하지 않으며 Linux 파일 시스템에서는 대/소문자를 구분합니다.
일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.
적용 대상
GetFileSystemEntries(String, String, SearchOption)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
지정된 경로의 검색 패턴과 일치하는 모든 파일 이름 및 디렉터리 이름의 배열을 반환하고 선택적으로 하위 디렉터리를 검색합니다.
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()
매개 변수
- path
- String
검색할 디렉터리의 상대 또는 절대 경로입니다. 이 문자열은 대/소문자를 구분하지 않습니다.
- searchPattern
- String
에서 파일 및 디렉터리 이름과 일치시킬 검색 문자열입니다 path. 이 매개 변수는 유효한 리터럴 경로와 와일드카드(* 및 ?) 문자의 조합을 포함할 수 있지만 정규식을 지원하지는 않습니다.
- searchOption
- SearchOption
검색 작업에 현재 디렉터리만 포함할지 아니면 모든 하위 디렉터리를 포함해야 하는지를 지정하는 열거형 값 중 하나입니다. 기본값은 TopDirectoryOnly입니다.
반품
지정된 검색 조건과 일치하는 파일 이름 및 디렉터리 이름 또는 파일 또는 디렉터리를 찾을 수 없는 경우 빈 배열의 배열입니다.
예외
.NET Framework 및 .NET Core 버전이 2.1보다 오래된 경우: path 길이가 0인 문자열이거나 공백만 포함하거나 잘못된 문자를 포함합니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars() 수 있습니다.
-또는-
searchPattern 은 유효한 패턴을 포함하지 않습니다.
searchOption 가 유효한 SearchOption 값이 아닌 경우
path 가 잘못되었습니다(예: 매핑되지 않은 드라이브를 참조하는 경우).
path 은 파일 이름입니다.
지정된 경로, 파일 이름 또는 결합이 시스템 정의 최대 길이를 초과합니다.
호출자에게 필요한 권한이 없습니다.
호출자에게 필요한 권한이 없습니다.
설명
반환된 파일 및 디렉터리 이름의 순서는 보장되지 않습니다. 특정 정렬 순서가 Sort 필요한 경우 메서드를 사용합니다.
searchPattern 는 리터럴과 와일드카드 문자의 조합일 수 있지만 정규식을 지원하지는 않습니다. 다음 와일드카드 지정자는 .에서 searchPattern허용됩니다.
| 와일드카드 지정자 | 검색 결과 |
|---|---|
| * (별표) | 해당 위치에 있는 문자가 0개 이상입니다. |
| ? (물음표) | 정확히 그 위치에 있는 한 문자입니다. |
와일드카드 이외의 문자는 리터럴 문자입니다. 예를 들어 searchPattern 문자열 "*t"는 문자 "t"로 끝나는 모든 이름을 path 검색합니다. 문자열 "s*"는 searchPattern 문자 "s"로 path 시작하는 모든 이름을 검색합니다.
searchPattern 는 두 개의 마침표("..")로 끝나거나 두 개의 마침표("..") DirectorySeparatorChar 를 포함하거나 AltDirectorySeparatorChar잘못된 문자를 포함할 수 없습니다. 메서드를 사용하여 잘못된 문자를 쿼리할 GetInvalidPathChars 수 있습니다.
메모
"*.txt"와 같은 별표 와일드카드 문자를 searchPattern 사용하면 지정된 확장의 문자 수가 다음과 같이 검색에 영향을 줍니다.
- 지정된 확장의 길이가 정확히 3자인 경우 메서드는 지정된 확장명으로 시작하는 확장명을 가진 파일을 반환합니다. 예를 들어 "*.xls"는 "book.xls" 및 "book.xlsx"를 모두 반환합니다.
- 다른 모든 경우에서 메서드는 지정된 확장과 정확히 일치하는 파일을 반환합니다. 예를 들어 "*.ai"는 "file.ai"를 반환하지만 "file.aif"는 반환하지 않습니다.
물음표 와일드카드 문자를 사용하는 경우 이 메서드는 지정된 파일 확장과 일치하는 파일만 반환합니다. 예를 들어 디렉터리에서 "file1.txt" 및 "file1.txtother"라는 두 개의 파일이 "file?.txt"는 첫 번째 파일만 반환하지만 "file*.txt"의 검색 패턴은 두 파일을 모두 반환합니다.
메서드 및 EnumerateFileSystemEntries 메서드는 GetFileSystemEntries 다음과 같이 다릅니다. 사용할 EnumerateFileSystemEntries때 전체 컬렉션이 반환되기 전에 항목 컬렉션을 열거할 수 있습니다. 사용할 GetFileSystemEntries경우 배열에 액세스하기 전에 전체 항목 배열이 반환될 때까지 기다려야 합니다. 따라서 많은 파일 및 디렉터리 EnumerateFileSystemEntries 로 작업하는 경우 더 효율적일 수 있습니다.
매개 변수를 path 사용하여 상대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 메서드를 사용하여 GetCurrentDirectory 확인할 수 있는 현재 작업 디렉터리를 기준으로 해석됩니다.