DirectoryInfo.CreateSubdirectory 메서드

정의

지정된 경로에 하위 디렉터리를 하나 이상 만듭니다. 지정된 경로는 DirectoryInfo 클래스의 이 인스턴스에 대한 상대적 경로일 수 있습니다.

오버로드

CreateSubdirectory(String)

지정된 경로에 하위 디렉터리를 하나 이상 만듭니다. 지정된 경로는 DirectoryInfo 클래스의 이 인스턴스에 대한 상대적 경로일 수 있습니다.

CreateSubdirectory(String, DirectorySecurity)

지정된 경로에 지정된 보안을 사용하여 하위 디렉터리를 하나 이상 만듭니다. 지정된 경로는 DirectoryInfo 클래스의 이 인스턴스에 대한 상대적 경로일 수 있습니다.

CreateSubdirectory(String)

Source:
DirectoryInfo.cs
Source:
DirectoryInfo.cs
Source:
DirectoryInfo.cs

지정된 경로에 하위 디렉터리를 하나 이상 만듭니다. 지정된 경로는 DirectoryInfo 클래스의 이 인스턴스에 대한 상대적 경로일 수 있습니다.

public:
 System::IO::DirectoryInfo ^ CreateSubdirectory(System::String ^ path);
public System.IO.DirectoryInfo CreateSubdirectory (string path);
member this.CreateSubdirectory : string -> System.IO.DirectoryInfo
Public Function CreateSubdirectory (path As String) As DirectoryInfo

매개 변수

path
String

지정된 경로입니다. 이 경로는 다른 디스크 볼륨이나 UNC(Universal Naming Convention) 이름이 될 수 없습니다.

반환

path에 지정된 마지막 경로입니다.

예외

path가 올바른 파일 경로를 지정하지 않거나 잘못된 DirectoryInfo 문자를 포함합니다.

path이(가) null인 경우

지정된 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).

하위 디렉터리를 만들 수 없습니다.

또는

파일에 이미 로 지정된 이름이 있습니다 path.

지정된 경로, 파일 이름 또는 둘 다가 시스템에서 정의한 최대 길이를 초과합니다.

호출자가 디렉터리를 만들기 위한 코드 액세스 권한이 없습니다.

또는

호출자가 DirectoryInfo 개체가 설명하는 디렉터리를 읽기 위한 코드 액세스 권한이 없습니다. 이 문제는 path 매개 변수가 기존 디렉터리를 설명할 때 발생할 수 있습니다.

path에 드라이브 레이블("C:\")에 속하지 않는 콜론 문자(:)가 포함되어 있습니다.

예제

다음 예제에서는 하위 디렉터리를 만드는 방법을 보여 줍니다. 이 예제에서는 만든 디렉터리를 만든 후에 제거합니다. 따라서 이 샘플을 테스트하려면 코드에서 삭제 줄을 주석 처리합니다.

using namespace System;
using namespace System::IO;
int main()
{
   
   // Create a reference to a directory.
   DirectoryInfo^ di = gcnew DirectoryInfo( "TempDir" );
   
   // Create the directory only if it does not already exist.
   if ( di->Exists == false )
      di->Create();

   
   // Create a subdirectory in the directory just created.
   DirectoryInfo^ dis = di->CreateSubdirectory( "SubDir" );
   
   // Process that directory as required.
   // ...
   // Delete the subdirectory.
   dis->Delete( true );
   
   // Delete the directory.
   di->Delete( true );
}
using System;
using System.IO;

public class CreateSubTest
{
    public static void Main()
    {
        // Create a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");

        // Process that directory as required.
        // ...

        // Delete the subdirectory.
        dis.Delete(true);

        // Delete the directory.
        di.Delete(true);
    }
}
open System.IO

// Create a reference to a directory.
let di = DirectoryInfo "TempDir"

// Create the directory only if it does not already exist.
if not di.Exists then
    di.Create()

// Create a subdirectory in the directory just created.
let dis = di.CreateSubdirectory "SubDir"

// Process that directory as required.
// ...

// Delete the subdirectory.
dis.Delete true

// Delete the directory.
di.Delete true
Imports System.IO

Public Class CreateSubTest

    Public Shared Sub Main()
        ' Make a reference to a directory.
        Dim di As New DirectoryInfo("TempDir")

        ' Create the directory only if it does not already exist.
        If di.Exists = False Then
            di.Create()
        End If

        ' Create a subdirectory in the directory just created.
        Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir")

        ' Process that directory as required.
        ' ...

        ' Delete the subdirectory.
        dis.Delete(True)

        ' Delete the directory.
        di.Delete(True)
    End Sub
End Class

설명

의 일부가 path 유효하지 않은 경우 에 path 지정된 모든 디렉터리를 만듭니다. 매개 변수는 path 파일 경로가 아닌 디렉터리 경로를 지정합니다. 하위 디렉터리가 이미 있는 경우 이 메서드는 아무 것도 수행하지 않습니다.

일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

추가 정보

적용 대상

CreateSubdirectory(String, DirectorySecurity)

지정된 경로에 지정된 보안을 사용하여 하위 디렉터리를 하나 이상 만듭니다. 지정된 경로는 DirectoryInfo 클래스의 이 인스턴스에 대한 상대적 경로일 수 있습니다.

public:
 System::IO::DirectoryInfo ^ CreateSubdirectory(System::String ^ path, System::Security::AccessControl::DirectorySecurity ^ directorySecurity);
public System.IO.DirectoryInfo CreateSubdirectory (string path, System.Security.AccessControl.DirectorySecurity directorySecurity);
member this.CreateSubdirectory : string * System.Security.AccessControl.DirectorySecurity -> System.IO.DirectoryInfo
Public Function CreateSubdirectory (path As String, directorySecurity As DirectorySecurity) As DirectoryInfo

매개 변수

path
String

지정된 경로입니다. 이 경로는 다른 디스크 볼륨이나 UNC(Universal Naming Convention) 이름이 될 수 없습니다.

directorySecurity
DirectorySecurity

적용할 보안입니다.

반환

path에 지정된 마지막 경로입니다.

예외

path가 올바른 파일 경로를 지정하지 않거나 잘못된 DirectoryInfo 문자를 포함합니다.

path이(가) null인 경우

지정된 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).

하위 디렉터리를 만들 수 없습니다.

또는

path에 지정된 이름을 갖는 파일 또는 디렉터리가 이미 있습니다.

지정된 경로, 파일 이름 또는 둘 다가 시스템에서 정의한 최대 길이를 초과합니다.

호출자가 디렉터리를 만들기 위한 코드 액세스 권한이 없습니다.

또는

호출자가 DirectoryInfo 개체가 설명하는 디렉터리를 읽기 위한 코드 액세스 권한이 없습니다. 이 문제는 path 매개 변수가 기존 디렉터리를 설명할 때 발생할 수 있습니다.

path에 드라이브 레이블("C:\")에 속하지 않는 콜론 문자(:)가 포함되어 있습니다.

설명

의 일부가 path 유효하지 않은 경우 에 path 지정된 모든 디렉터리를 만듭니다. 매개 변수는 path 파일 경로가 아닌 디렉터리 경로를 지정합니다. 하위 디렉터리가 이미 있는 경우 이 메서드는 아무 것도 수행하지 않습니다.

일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

적용 대상