aqFile.GetLastWriteTime Method

Applies to TestComplete 15.63, last modified on April 23, 2024

Description

Use the GetLastWriteTime method to determine when the file was last modified. To assign a new date and/or time of file modification, use the SetLastWriteTime method.

Declaration

aqFile.GetLastWriteTime(PathToFile)

PathToFile [in]    Required    String    
Result Date/Time

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PathToFile

Specifies the fully-qualified path to the desired file.

Result Value

A Date object that stores the date when the file was last modified.

Example

The code below creates a file, writes some data to it and reads the file content. After that, it posts the time when the file was created, last modified and last accessed to the test log and deletes the file.

JavaScript, JScript

function GetTimeExample()
{
 var sPath = "C:\\Temp\\TempFile.txt";

 // Creates a file
 aqFile.Create(sPath);
 
 // Retards script execution
 Delay(2000);
 
 // Writes data to the file
 aqFile.WriteToTextFile(sPath, "Hello, World!", aqFile.ctANSI, false);
 
 // Retards script execution
 Delay(2000);
 
 // Reads file content
 aqFile.ReadWholeTextFile(sPath, aqFile.ctANSI);
 
 // Posts file creation time to the test log
 Log.Message(aqFile.GetCreationTime(sPath));
 // Posts file last write time to the test log
 Log.Message(aqFile.GetLastWriteTime(sPath));
 // Posts file last access time to the test log
 Log.Message(aqFile.GetLastAccessTime(sPath));
 
 // Deletes the file
 aqFile.Delete(sPath);
}

Python

def GetTimeExample():
  sPath = "C:\\Temp\\TempFile.txt"
  # Creates a file
  aqFile.Create(sPath)
  # Retards script execution
  Delay(2000);
  
  # Writes data to the file
  aqFile.WriteToTextFile(sPath, "Hello, World!", aqFile.ctANSI, False)
  # Retards script execution
  Delay(2000);
  
  # Reads file content
  aqFile.ReadWholeTextFile(sPath, aqFile.ctANSI)
  
  # Posts file creation time to the test log
  Log.Message(aqFile.GetCreationTime(sPath))
  # Posts file last write time to the test log
  Log.Message(aqFile.GetLastWriteTime(sPath))
  # Posts file last access time to the test log
  Log.Message(aqFile.GetLastAccessTime(sPath))
  
  # Deletes the file
  aqFile.Delete(sPath)

VBScript

Sub GetTimeExample

 sPath = "C:\Temp\TempFile.txt"

 ' Creates a file
 Call aqFile.Create(sPath)
 
 ' Retards script execution
 Call Delay(2000)
 
 ' Writes data to the file
 Call aqFile.WriteToTextFile(sPath, "Hello, World!", aqFile.ctANSI, false)
 
 ' Retards script execution
 Call Delay(2000)
 
 ' Reads file content
 Call aqFile.ReadWholeTextFile(sPath, aqFile.ctANSI)
 
 ' Posts file creation time to the test log
 Call Log.Message(aqFile.GetCreationTime(sPath))
 ' Posts file last write time to the test log
 Call Log.Message(aqFile.GetLastWriteTime(sPath))
 ' Posts file last access time to the test log
 Call Log.Message(aqFile.GetLastAccessTime(sPath))
 
 ' Deletes the file
 Call aqFile.Delete(sPath)
End Sub

DelphiScript

function GetTimeExample;
 var sPath;

begin
 sPath := 'C:\Temp\TempFile.txt';

 // Creates a file
 aqFile.Create(sPath);
 
 // Retards script execution
 Delay(2000);
 
 // Writes data to the file
 aqFile.WriteToTextFile(sPath, 'Hello, World!', aqFile.ctANSI, false);
 
 // Retards script execution
 Delay(2000);
 
 // Reads file content
 aqFile.ReadWholeTextFile(sPath, aqFile.ctANSI);
 
 // Posts file creation time to the test log
 Log.Message(aqFile.GetCreationTime(sPath));
 // Posts file last write time to the test log
 Log.Message(aqFile.GetLastWriteTime(sPath));
 // Posts file last access time to the test log
 Log.Message(aqFile.GetLastAccessTime(sPath));
 
 // Deletes the file
 aqFile.Delete(sPath);
end;

C++Script, C#Script

function GetTimeExample()
{
 var sPath = "C:\\Temp\\TempFile.txt";

 // Creates a file
 aqFile["Create"](sPath);
 
 // Retards script execution
 Delay(2000);
 
 // Writes data to the file
 aqFile["WriteToTextFile"]( sPath, "Hello, World!", aqFile.ctANSI, false );
 
 // Retards script execution
 Delay(2000);
 
 // Reads file content
 aqFile["ReadWholeTextFile"]( sPath, aqFile.ctANSI );
 
 // Posts file creation time to the test log
 Log["Message"]( aqFile["GetCreationTime"](sPath) );
 // Posts file last write time to the test log
 Log["Message"]( aqFile["GetLastWriteTime"](sPath) );
 // Posts file last access time to the test log
 Log["Message"]( aqFile["GetLastAccessTime"](sPath) );
 
 // Deletes the file
 aqFile["Delete"](sPath);
}

See Also

Working With Files From Scripts
GetCreationTime Method
GetLastAccessTime Method
SetLastWriteTime Method
DateLastModified Property

Highlight search results