aqFile.GetLastAccessTime Method

Applies to TestComplete 14.20, last modified on September 11, 2019

Description

Use the GetLastAccessTime method to determine the time the file was last accessed. To assign a new date and/or time of the last access, use the SetLastAccessTime method.

Declaration

aqFile.GetLastAccessTime(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/time when the file was last accessed.

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
aqFile.GetCreationTime Method
aqFile.GetLastWriteTime Method
aqFile.SetLastAccessTime Method
DateLastAccessed Property

Highlight search results