Directory.GetCreationTime(String) 메서드

정의

디렉터리를 만든 날짜와 시간을 가져옵니다.

public:
 static DateTime GetCreationTime(System::String ^ path);
public static DateTime GetCreationTime (string path);
static member GetCreationTime : string -> DateTime
Public Shared Function GetCreationTime (path As String) As DateTime

매개 변수

path
String

디렉터리 경로입니다.

반환

DateTime

지정된 디렉터리를 만든 날짜와 시간으로 설정된 구조체입니다. 이 값은 현지 시간으로 표현됩니다.

예외

호출자에게 필요한 권한이 없는 경우

2.1보다 오래된 .NET Framework 및 .NET Core 버전: path 길이가 0인 문자열이거나, 공백만 포함하거나, 하나 이상의 잘못된 문자를 포함합니다. GetInvalidPathChars() 메서드를 사용하여 잘못된 문자를 쿼리할 수 있습니다.

path이(가) null인 경우

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

예제

다음 예제에서는 지정된 디렉터리의 생성 시간을 가져옵니다.

using namespace System;
using namespace System::IO;
int main()
{
   try
   {
      
      // Get the creation time of a well-known directory.
      DateTime dt = Directory::GetCreationTime( Environment::CurrentDirectory );
      
      // Give feedback to the user.
      if ( DateTime::Now.Subtract( dt ).TotalDays > 364 )
      {
         Console::WriteLine( "This directory is over a year old." );
      }
      else
      if ( DateTime::Now.Subtract( dt ).TotalDays > 30 )
      {
         Console::WriteLine( "This directory is over a month old." );
      }
      else
      if ( DateTime::Now.Subtract( dt ).TotalDays <= 1 )
      {
         Console::WriteLine( "This directory is less than a day old." );
      }
      else
      {
         Console::WriteLine( "This directory was created on {0}", dt );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The process failed: {0}", e );
   }

}
using System;
using System.IO;

class Test
{
    public static void Main()
    {
        try
        {
            // Get the creation time of a well-known directory.
            DateTime dt = Directory.GetCreationTime(Environment.CurrentDirectory);

            // Give feedback to the user.
            if (DateTime.Now.Subtract(dt).TotalDays > 364)
            {
                Console.WriteLine("This directory is over a year old.");
            }
            else if (DateTime.Now.Subtract(dt).TotalDays > 30)
            {
                Console.WriteLine("This directory is over a month old.");
            }
            else if (DateTime.Now.Subtract(dt).TotalDays <= 1)
            {
                Console.WriteLine("This directory is less than a day old.");
            }
            else
            {
                Console.WriteLine("This directory was created on {0}", dt);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
open System
open System.IO

try
    // Get the creation time of a well-known directory.
    let dt = Directory.GetCreationTime Environment.CurrentDirectory

    // Give feedback to the user.
    if DateTime.Now.Subtract(dt).TotalDays > 364 then
        printfn "This directory is over a year old."
    elif DateTime.Now.Subtract(dt).TotalDays > 30 then
        printfn "This directory is over a month old."
    elif DateTime.Now.Subtract(dt).TotalDays <= 1 then
        printfn "This directory is less than a day old."
    else
        printfn $"This directory was created on {dt}"
with e ->
    printfn $"The process failed: {e}"
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Try
            ' Get the creation time of a well-known directory.
            Dim dt As DateTime = Directory.GetCreationTime(Environment.CurrentDirectory)

            ' Give feedback to the user.
            If DateTime.Now.Subtract(dt).TotalDays > 364 Then
                Console.WriteLine("This directory is over a year old.")
            ElseIf DateTime.Now.Subtract(dt).TotalDays > 30 Then
                Console.WriteLine("This directory is over a month old.")
            ElseIf DateTime.Now.Subtract(dt).TotalDays <= 1 Then
                Console.WriteLine("This directory is less than a day old.")
            Else
                Console.WriteLine("This directory was created on {0}", dt)
            End If

        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class

설명

참고

이 메서드는 운영 체제에서 값을 지속적으로 업데이트하지 않을 수 있는 네이티브 함수를 사용하기 때문에 부정확한 값을 반환할 수 있습니다.

이 메서드는 File.GetCreationTime.

매개 변수에 설명된 디렉터리가 없으면 이 메서드는 1601년 path 1월 1일 자정 12:00을 반환합니다. (C.E.) 현지 시간으로 조정된 UTC(협정 세계시)입니다.

path 매개 변수는 상대 또는 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리를 기준으로 해석됩니다. 현재 작업 디렉터리를 가져오려면 다음을 참조하세요 GetCurrentDirectory.

매개 변수는 path 대/소문자를 구분하지 않습니다.

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

적용 대상

추가 정보