File.GetLastWriteTime Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Aşırı Yüklemeler
GetLastWriteTime(String) |
Belirtilen dosya veya dizinin son yazıldığı tarih ve saati döndürür. |
GetLastWriteTime(SafeFileHandle) |
Belirtilen dosya veya dizinin son yazma tarihini ve saatini döndürür. |
GetLastWriteTime(String)
- Kaynak:
- File.cs
- Kaynak:
- File.cs
- Kaynak:
- File.cs
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
Yazma tarihi ve saat bilgilerinin alındığı dosya veya dizin.
Döndürülenler
DateTime 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öntemini kullanarak 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.
path
geçersiz bir biçimde.
Örnekler
Aşağıdaki örnekte gösterilmiştir GetLastWriteTime
.
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
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 dt2 = File.GetLastWriteTime path
printfn $"The last write time for this file was {dt2}."
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 some 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
Not
Değerleri işletim sistemi tarafından sürekli güncelleştirilmeyebilecek yerel işlevler kullandığından bu yöntem yanlış bir değer döndürebilir. Her işletim sistemi, son yazma zamanını kendi kurallarına göre yönetir. Performansı artırmak için, bir işletim sistemi son yazma zamanı değerini son yazma işleminin tam zamanına ayarlamayabilir, ancak bunun yerine yakın bir yaklaşık değere ayarlayabilir.
parametresinde path
açıklanan dosya yoksa, bu yöntem 12:00 gece yarısı, 1 Ocak 1601 A.D. (C.E.) döndürür. Eşgüdümlü Evrensel Saat (UTC), yerel saate 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. .
Yaygın G/Ç görevlerinin listesi için bkz. Ortak G/Ç Görevleri.
Ayrıca bkz.
Şunlara uygulanır
GetLastWriteTime(SafeFileHandle)
- Kaynak:
- File.cs
- Kaynak:
- File.cs
- Kaynak:
- File.cs
Belirtilen dosya veya dizinin son yazma tarihini ve saatini döndürür.
public:
static DateTime GetLastWriteTime(Microsoft::Win32::SafeHandles::SafeFileHandle ^ fileHandle);
public static DateTime GetLastWriteTime (Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle);
static member GetLastWriteTime : Microsoft.Win32.SafeHandles.SafeFileHandle -> DateTime
Public Shared Function GetLastWriteTime (fileHandle As SafeFileHandle) As DateTime
Parametreler
- fileHandle
- SafeFileHandle
Son yazma tarih ve saat bilgilerinin alındığı dosya veya dizine A SafeFileHandle .
Döndürülenler
DateTime Belirtilen dosya veya dizin için son yazma tarihi ve saati olarak ayarlanmış bir yapı. Bu değer yerel saatle ifade edilir.
Özel durumlar
fileHandle
, null
değeridir.
Çağıranın gerekli izni yok.
Şunlara uygulanır
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin