Returns the date and time the specified file or directory was last written to.
Public Shared Function GetLastWriteTime ( _ path As String _ ) As DateTime
Dim path As String Dim returnValue As DateTime returnValue = File.GetLastWriteTime(path)
public static DateTime GetLastWriteTime( string path )
public: static DateTime GetLastWriteTime( String^ path )
public static function GetLastWriteTime( path : String ) : DateTime
The caller does not have the required permission.
path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
path is nullNothingnullptra null reference (Nothing in Visual Basic).
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
path is in an invalid format.
If the file described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.
For a list of common I/O tasks, see Common I/O Tasks.
The following example demonstrates GetLastWriteTime.
Imports System 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
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()); } } }
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 ); } }
for reading from the specified file. Associated enumeration: FileIOPermissionAccess..::.Read
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune