FileSystemInfo.LastWriteTime 속성

정의

현재 파일이나 디렉터리에 마지막으로 쓴 시간을 가져오거나 설정합니다.

public:
 property DateTime LastWriteTime { DateTime get(); void set(DateTime value); };
public DateTime LastWriteTime { get; set; }
member this.LastWriteTime : DateTime with get, set
Public Property LastWriteTime As DateTime

속성 값

DateTime

현재 파일에 마지막으로 쓴 시간입니다.

예외

Refresh()가 데이터를 초기화할 수 없는 경우

현재 운영 체제가 Windows NT 이상이 아닙니다.

호출자가 잘못된 쓰기 시간을 설정하려고 시도합니다.

예제

다음 코드 예제에서는 "터치" 작업을 통해 속성을 업데이트 LastWriteTime 하는 방법을 보여 줍니다. 이 예제에서 파일은 "터치"되어 현재 LastAccessTime 날짜 및 시간으로 속성 및 LastWriteTime 속성을 업데이트CreationTime합니다.

using System;
using System.IO;

namespace touch
{
    class Touch
    {
        static void Main(string[] args)
        {
            // Make sure a filename was provided.
            if (args.Length > 0)
            {
                // Verify that the provided filename exists.
                if (File.Exists(args[0]))
                {
                    FileInfo fi = new FileInfo(args[0]);
                    touchFile(fi);
                }
                else
                {
                    Console.WriteLine(
                        "Could not find the file: {0}.", args[0]);
                }
            }
            else
            {
                Console.WriteLine("No file was specified.");
            }
        }

        static void touchFile(FileSystemInfo fsi)
        {
            Console.WriteLine("Touching: {0}", fsi.FullName);

            // Update the CreationTime, LastWriteTime and LastAccessTime.
            try
            {
                fsi.CreationTime = fsi.LastWriteTime = fsi.LastAccessTime =
                    DateTime.Now;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }
        }
    }
}
Imports System.IO

Public Class Touch
    Public Shared Sub Main(ByVal args() As String)

        ' Make sure an argument (filename) was provided.
        If args.Length > 0 Then

            ' Verify that the provided filename exists.
            If File.Exists(args(0)) Then
                Dim fi As FileInfo = New FileInfo(args(0))
                touchFile(fi)
            Else
                Console.WriteLine("Could not find the file {0}", args(0))
            End If
        Else
            Console.WriteLine("No file specified.")
        End If
    End Sub

    Public Shared Sub touchFile(ByVal fsi As FileSystemInfo)
        Console.WriteLine("Touching: {0}", fsi.FullName)

        ' Update the CreationTime, LastWriteTime and LastAccessTime.
        Try
            fsi.CreationTime = DateTime.Now
            fsi.LastAccessTime = DateTime.Now
            fsi.LastWriteTime = DateTime.Now
        Catch e As Exception
            Console.WriteLine("Error: {0}", e.Message)
        End Try

    End Sub

End Class

설명

참고

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

다음 DirectoryInfo 메서드 중 하나에서 개체의 LastWriteTime 현재 인스턴스 FileSystemInfo 가 반환된 경우 속성 값이 미리 캐시됩니다.

최신 값을 얻으려면 메서드를 호출합니다 Refresh .

개체에 FileSystemInfo 설명된 파일 또는 디렉터리가 없거나 이 파일 또는 디렉터리가 포함된 파일 시스템이 이 정보를 지원하지 않는 경우 이 속성은 1601년 1월 1일 자정 12:00을 반환합니다. (C.E.) 현지 시간으로 조정된 UTC(협정 세계시).

적용 대상

추가 정보