Directory.GetLastWriteTime(String) Yöntem

Tanım

Belirtilen dosya veya dizinin son yazıldığı tarih ve saati döndürür.

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

Parametreler

path
String

Değişiklik tarih ve saat bilgilerinin alındığı dosya veya dizin.

Döndürülenler

Belirtilen dosya veya dizinin son yazıldığı tarih ve saate ayarlanmış bir yapı. Bu değer yerel saatle ifade edilir.

Özel durumlar

Çağıranın gerekli izni yok.

2.1'den eski .NET Framework ve .NET Core sürümleri: path sıfır uzunlukta bir dizedir, yalnızca boşluk içerir veya bir veya daha fazla geçersiz karakter içerir. yöntemiyle GetInvalidPathChars() geçersiz karakterleri sorgulayabilirsiniz.

path, null değeridir.

Belirtilen yol, dosya adı veya her ikisi birden sistem tarafından tanımlanan en fazla uzunluğu aşıyor.

Örnekler

Aşağıdaki örnekte nasıl kullanılacağı GetLastWriteTimegösterilmektedir.

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 );
   }

}
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());
        }
    }
}
open System
open System.IO

try
    let path = @"c:\MyDir"
    if not (Directory.Exists path) then
        Directory.CreateDirectory path |> ignore
    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.
    let dt = Directory.GetLastWriteTime path
    printfn $"The last write time for this directory was {dt}"
    
    // Update the last write time.
    Directory.SetLastWriteTime(path, DateTime.Now)
    let dt = Directory.GetLastWriteTime path
    printfn $"The last write 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)
            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

Açıklamalar

Not

Bu yöntem, değerleri işletim sistemi tarafından sürekli güncelleştirilemeyen yerel işlevler kullandığından yanlış bir değer döndürebilir.

parametresinde path açıklanan dizin yoksa, bu yöntem 1 Ocak 1601'de gece yarısı 12:00'yi (C.E.) döndürür. Eşgüdümlü Evrensel Saat (UTC), yerel saate göre ayarlanır.

parametresinin path göreli veya mutlak yol bilgilerini belirtmesine izin verilir. Göreli yol bilgisi, geçerli çalışma dizinine göre yorumlanır. Geçerli çalışma dizinini edinmek için bkz GetCurrentDirectory. .

parametresinin path büyük/küçük harf duyarlılığı, kodun üzerinde çalıştığı dosya sistemine karşılık gelir. Örneğin, NTFS'de (varsayılan Windows dosya sistemi) büyük/küçük harfe duyarlı değildir ve Linux dosya sistemlerinde büyük/küçük harfe duyarlıdır.

Yaygın G/Ç görevlerinin listesi için bkz. Ortak G/Ç Görevleri.

Şunlara uygulanır

Ayrıca bkz.