File.SetLastWriteTime Yöntem

Tanım

Aşırı Yüklemeler

Name Description
SetLastWriteTime(SafeFileHandle, DateTime)

Belirtilen dosya veya dizinin son yazıldığı tarih ve saati ayarlar.

SetLastWriteTime(String, DateTime)

Belirtilen dosyanın son yazıldığı tarih ve saati ayarlar.

SetLastWriteTime(SafeFileHandle, DateTime)

Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs

Belirtilen dosya veya dizinin son yazıldığı tarih ve saati ayarlar.

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)

Parametreler

fileHandle
SafeFileHandle

SafeFileHandle Son yazma tarihi ve saat bilgisinin ayarlanacağı dosya veya dizine A.

lastWriteTime
DateTime

DateTime son yazma tarihi ve saati için ayarlanacağı değeri içeren.fileHandle Bu değer yerel saatle ifade edilir.

Özel durumlar

fileHandle, null'e eşittir.

lastWriteTime bu işlem için izin verilen tarih, saat veya her ikisi aralığı dışında bir değer belirtir.

Çağıranın gerekli izni yok.

İşlem gerçekleştirilirken G/Ç hatası oluştu.

Şunlara uygulanır

SetLastWriteTime(String, DateTime)

Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs

Belirtilen dosyanın son yazıldığı tarih ve saati ayarlar.

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)

Parametreler

path
String

Tarih ve saat bilgilerinin ayarlanacağı dosya.

lastWriteTime
DateTime

DateTime son yazma tarihi ve saati için ayarlanacağı değeri içeren.path Bu değer yerel saatle ifade edilir.

Özel durumlar

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. GetInvalidPathChars() yöntemini kullanarak geçersiz karakterleri sorgulayabilirsiniz.

path, null'e eşittir.

Belirtilen yol, dosya adı veya her ikisi de sistem tanımlı uzunluk üst sınırını aşıyor.

Belirtilen yol bulunamadı.

Çağıranın gerekli izni yok.

path geçersiz biçimde.

lastWriteTime bu işlem için izin verilen tarih veya saat aralığının dışında bir değer belirtir.

Örnekler

Aşağıdaki örnek, belirtilen dosya için dosya sistemini denetler, gerekirse dosyayı oluşturur ve ardından dosyanın son yazma zamanını ayarlar ve alır.

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

Açıklamalar

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

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

Ayrıca bkz.

Şunlara uygulanır