다음을 통해 공유


Directory.GetLastWriteTime 메서드

지정된 파일 또는 디렉터리를 마지막으로 쓴 날짜와 시간을 반환합니다.

네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function GetLastWriteTime ( _
    path As String _
) As DateTime
‘사용 방법
Dim path As String
Dim returnValue As DateTime

returnValue = Directory.GetLastWriteTime(path)
public static DateTime GetLastWriteTime (
    string path
)
public:
static DateTime GetLastWriteTime (
    String^ path
)
public static DateTime GetLastWriteTime (
    String path
)
public static function GetLastWriteTime (
    path : String
) : DateTime

매개 변수

  • path
    수정 날짜와 시간 정보를 가져올 파일 또는 디렉터리입니다.

반환 값

지정된 파일 또는 디렉터리를 마지막으로 쓴 날짜와 시간으로 설정된 DateTime 구조체입니다. 이 값은 현지 시간으로 표현됩니다.

예외

예외 형식 조건

IOException

지정된 경로를 찾을 수 없는 경우

UnauthorizedAccessException

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

ArgumentException

path가 길이가 0인 문자열이거나, 공백만 포함하거나 또는 InvalidPathChars로 정의된 하나 이상의 잘못된 문자를 포함하는 경우

ArgumentNullException

path가 Null 참조(Visual Basic의 경우 Nothing)인 경우

PathTooLongException

지정된 경로 또는 파일 이름이 시스템에 정의된 최대 길이를 초과하는 경우 예를 들어, Windows 기반 플랫폼에서는 경로에 248자 미만의 문자를 사용해야 하며 파일 이름에는 260자 미만의 문자를 사용해야 합니다.

설명

path 매개 변수에는 상대 경로나 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리에 상대적으로 해석됩니다. 현재 작업 디렉터리를 얻는 방법에 대해서는 GetCurrentDirectory를 참조하십시오.

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

다음 표에서는 일반적인 예 또는 관련된 I/O 작업의 예를 보여 줍니다.

수행 작업

참조 항목

텍스트 파일을 만듭니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에 씁니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에서 읽습니다.

방법: 파일의 텍스트 읽기

디렉터리를 삭제합니다.

Delete

Delete

디렉터리의 하위 디렉터리를 참조하십시오.

GetDirectories

GetDirectories

디렉터리의 크기를 찾습니다.

Directory

예제

다음 코드 예제에서는 GetLastWriteTime을 보여 줍니다.

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Try
            Dim path As String = "c:\MyDir"
            If Directory.Exists(path) = False Then
                Directory.CreateDirectory(path)
            Else
                ' Take an action which will affect the write time.
                Directory.SetLastWriteTime(path, New DateTime(1985, 4, 3))
            End If

            ' Get the creation time of a well-known directory.
            Dim dt As DateTime = Directory.GetLastWriteTime(path)
            Console.WriteLine("The last write time for this directory was {0}", dt)

            ' Update the last write time.
            Directory.SetLastWriteTime(path, DateTime.Now)
            dt = Directory.GetLastWriteTime(path)
            Console.WriteLine("The last write time for this directory was {0}", dt)

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

class Test 
{
    public static void Main() 
    {
        try 
        {
            string path = @"c:\MyDir";
            if (!Directory.Exists(path)) 
            {
                Directory.CreateDirectory(path);
            } 
            else 
            {
                // Take an action which will affect the write time.
                Directory.SetLastWriteTime(path, new DateTime(1985,4,3));
            }

            // Get the creation time of a well-known directory.
            DateTime dt = Directory.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this directory was {0}", dt);
            
            // Update the last write time.
            Directory.SetLastWriteTime(path, DateTime.Now);
            dt = Directory.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this directory was {0}", dt);
        } 

        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
using namespace System;
using namespace System::IO;
int main()
{
   try
   {
      String^ path = "c:\\MyDir";
      if (  !Directory::Exists( path ) )
      {
         Directory::CreateDirectory( path );
      }
      else
      {
         
         // Take an action which will affect the write time.
         Directory::SetLastWriteTime( path, DateTime(1985,4,3) );
      }
      
      // Get the creation time of a well-known directory.
      DateTime dt = Directory::GetLastWriteTime( path );
      Console::WriteLine( "The last write time for this directory was {0}", dt );
      
      // Update the last write time.
      Directory::SetLastWriteTime( path, DateTime::Now );
      dt = Directory::GetLastWriteTime( path );
      Console::WriteLine( "The last write time for this directory was {0}", dt );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The process failed: {0}", e );
   }

}
import System.*;
import System.IO.*;

class Test
{
    public static void main(String[] args)
    {
        try {
            String path = "c:\\MyDir";

            if (!(Directory.Exists(path))) {
                Directory.CreateDirectory(path);
            }
            else {
                // Take an action which will affect the write time.
                Directory.SetLastWriteTime(path, new DateTime(1985, 4, 3));
            }

            // Get the creation time of a well-known directory.
            DateTime dt = Directory.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this directory was {0}",
                dt);

            // Update the last write time.
            Directory.SetLastWriteTime(path, DateTime.get_Now());
            dt = Directory.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this directory was {0}",
                dt);
        }
        catch (System.Exception e) {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    } //main
} //Test

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Directory 클래스
Directory 멤버
System.IO 네임스페이스

기타 리소스

파일 및 스트림 I/O
방법: 파일의 텍스트 읽기
방법: 파일에 텍스트 쓰기