File.SetLastWriteTime 메서드

정의

오버로드

SetLastWriteTime(SafeFileHandle, DateTime)

지정된 파일 또는 디렉터리가 마지막으로 기록된 날짜와 시간을 설정합니다.

SetLastWriteTime(String, DateTime)

지정된 파일에 마지막으로 쓴 날짜와 시간을 설정합니다.

SetLastWriteTime(SafeFileHandle, DateTime)

Source:
File.cs
Source:
File.cs
Source:
File.cs

지정된 파일 또는 디렉터리가 마지막으로 기록된 날짜와 시간을 설정합니다.

public:
 static void SetLastWriteTime(Microsoft::Win32::SafeHandles::SafeFileHandle ^ fileHandle, DateTime lastWriteTime);
public static void SetLastWriteTime (Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle, DateTime lastWriteTime);
static member SetLastWriteTime : Microsoft.Win32.SafeHandles.SafeFileHandle * DateTime -> unit
Public Shared Sub SetLastWriteTime (fileHandle As SafeFileHandle, lastWriteTime As DateTime)

매개 변수

fileHandle
SafeFileHandle

SafeFileHandle 마지막 쓰기 날짜 및 시간 정보를 설정할 파일 또는 디렉터리에 대한 입니다.

lastWriteTime
DateTime

DateTime에 마지막으로 쓴 날짜와 시간을 설정할 값이 포함된 fileHandle입니다. 이 값은 현지 시간으로 표현됩니다.

예외

fileHandlenull입니다.

lastWriteTime이 이 작업에 대해 허용되는 날짜나 시간 범위 또는 둘 다를 벗어나는 값을 지정합니다.

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

작업을 수행하는 동안 I/O 오류가 발생했습니다.

적용 대상

SetLastWriteTime(String, DateTime)

Source:
File.cs
Source:
File.cs
Source:
File.cs

지정된 파일에 마지막으로 쓴 날짜와 시간을 설정합니다.

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

매개 변수

path
String

날짜와 시간 정보를 설정할 파일입니다.

lastWriteTime
DateTime

DateTime에 마지막으로 쓴 날짜와 시간을 설정할 값이 포함된 path입니다. 이 값은 현지 시간으로 표현됩니다.

예외

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

path이(가) null인 경우

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

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

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

path의 형식이 잘못되었습니다.

lastWriteTime가 이 작업에 대해 허용되는 날짜 또는 시간 범위를 벗어나는 값을 지정합니다.

예제

다음 예제에서는 파일 시스템에서 지정된 파일을 확인하고 필요한 경우 파일을 만든 다음 파일의 마지막 쓰기 시간을 설정하고 가져옵니다.

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

}
using System;
using System.IO;

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

            // Get the creation time of a well-known directory.
            DateTime dt = File.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this file was {0}.", dt);
            
            // Update the last write time.
            File.SetLastWriteTime(path, DateTime.Now);
            dt = File.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this file was {0}.", dt);
        }
        catch (Exception e)
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
open System
open System.IO

try
    let path = @"c:\Temp\MyTest.txt"

    if File.Exists path |> not then
        File.Create path |> ignore
    else
        // Take an action that will affect the write time.
        File.SetLastWriteTime(path, DateTime(1985, 4, 3))

    // Get the creation time of a well-known directory.
    let dt = File.GetLastWriteTime path
    printfn $"The last write time for this file was {dt}."

    // Update the last write time.
    File.SetLastWriteTime(path, DateTime.Now)
    let dt = File.GetLastWriteTime path
    printfn $"The last write time for this file was {dt}."
with
| e -> printfn $"The process failed: {e}"
Imports System.IO
Imports System.Text

Public Class Test
    Public Shared Sub Main()
        Try
            Dim path As String = "c:\Temp\MyTest.txt"

            If File.Exists(path) = False Then
                File.Create(path)
            Else
                ' Take an action that will affect the write time.
                File.SetLastWriteTime(path, New DateTime(1985, 4, 3))
            End If

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

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

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

설명

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

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

추가 정보

적용 대상