Directory.SetLastAccessTime(String, DateTime) 메서드

정의

지정된 파일 또는 디렉터리에 마지막으로 액세스한 날짜와 시간을 설정합니다.

public:
 static void SetLastAccessTime(System::String ^ path, DateTime lastAccessTime);
public static void SetLastAccessTime(string path, DateTime lastAccessTime);
static member SetLastAccessTime : string * DateTime -> unit
Public Shared Sub SetLastAccessTime (path As String, lastAccessTime As DateTime)

매개 변수

path
String

액세스 날짜 및 시간 정보를 설정할 파일 또는 디렉터리입니다.

lastAccessTime
DateTime

액세스 날짜 및 시간에 대해 설정할 값이 들어 있는 개체입니다 path. 이 값은 현지 시간으로 표현됩니다.

예외

지정한 경로를 찾을 수 없습니다.

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

pathnull입니다.

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

호출자에게 필요한 권한이 없습니다.

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

lastAccessTime 는 이 작업에 허용되는 날짜 또는 시간 범위를 벗어난 값을 지정합니다.

예제

다음 예제에서는 사용 SetLastAccessTime하는 방법을 보여 줍니다.

using System;
using System.IO;

class Test
{
    public static void Main()
    {
        try
        {
            string path = @"c:\MyDir";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            Directory.SetLastAccessTime(path, new DateTime(1985,5,4));

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

        catch (Exception e)
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
open System
open System.IO

try
    let path = @"c:\MyDir"
    if not (Directory.Exists path) then
        Directory.CreateDirectory path |> ignore

    Directory.SetLastAccessTime(path, DateTime(1985,5,4))

    // Get the last access time of a well-known directory.
    let dt = Directory.GetLastAccessTime path
    printfn $"The last access time for this directory was {dt}"

    // Update the last access time.
    Directory.SetLastAccessTime(path, DateTime.Now)
    let dt = Directory.GetLastAccessTime path
    printfn $"The last access time for this directory was {dt}"

with e ->
    printfn $"The process failed: {e}"
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)
            End If
            Directory.SetLastAccessTime(path, New DateTime(1985, 5, 4))

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

            'Update the last access time.
            Directory.SetLastAccessTime(path, DateTime.Now)
            dt = Directory.GetLastAccessTime(path)
            Console.WriteLine("The last access 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

설명

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

매개 변수의 path 대/소문자 구분은 코드가 실행 중인 파일 시스템의 대/소문자 구분에 해당합니다. 예를 들어 NTFS(기본 Windows 파일 시스템)에서는 대/소문자를 구분하지 않으며 Linux 파일 시스템에서는 대/소문자를 구분합니다.

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

적용 대상

추가 정보