SetLastAccessTime Method

Applies to TestComplete 15.42, last modified on September 08, 2022

Description

Use the SetLastAccessTime method to set a new date and/or time of the last access to the file. To read the current last access date and time, read the DateCreated property.

Declaration

aqFileInfoObj.SetLastAccessTime(Time)

aqFileInfoObj An expression, variable or parameter that specifies a reference to an aqFileInfo object
Time [in]    Required    Date/Time    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Time

A Date object that specifies the new date and time to be set.

Result Value

True if the new date/time was set successfully, and False otherwise.

Example

The code below creates a file, sets a new time when this file was created, last accessed and modified and then posts the specified time values to the test log.

JavaScript, JScript

function SetTimeExample()
{
  sPath = "C:\\MyFiles\\FileName.txt";

  // Obtains information about the file
  FileInfo = aqFileSystem.GetFileInfo(sPath);

  // Specifies a new date of creation, last access and last modification
  CrtDate = aqDateTime.SetDateTimeElements(2010, 06, 30, 15, 24, 32);
  AccDate = aqDateTime.SetDateTimeElements(2010, 07, 02, 10, 54, 03);
  WrtDate = aqDateTime.SetDateTimeElements(2010, 07, 10, 11, 41, 53);
  
  // Creates a file
  aqFile.Create(sPath);
  
  // Sets a new time when the file was created, last accessed and modified
  FileInfo.SetCreationTime(CrtDate);
  FileInfo.SetLastAccessTime(AccDate);
  FileInfo.SetLastWriteTime(WrtDate);
  
  // Posts the specified time values to the test log
  Log.Message( FileInfo.GetCreationTime );
  Log.Message( FileInfo.GetLastAccessTime );
  Log.Message( FileInfo.GetLastWriteTime );
}

Python

def SetTimeExample():
  sPath = "C:\\MyFiles\\FileName.txt"
  # Obtains information about the file
  FileInfo = aqFileSystem.GetFileInfo(sPath)
  
  # Specifies a new date of creation, last access and last modification
  CrtDate = aqDateTime.SetDateTimeElements(2010, 6, 30, 15, 24, 32)
  AccDate = aqDateTime.SetDateTimeElements(2010, 7, 2, 10, 54, 3)
  WrtDate = aqDateTime.SetDateTimeElements(2010, 7, 10, 11, 41, 53)
  
  # Creates a file
  aqFile.Create(sPath)
  
  # Sets a new time when the file was created, last accessed and modified
  FileInfo.SetCreationTime(CrtDate)
  FileInfo.SetLastAccessTime(AccDate)
  FileInfo.SetLastWriteTime(WrtDate)
  
  # Posts the specified time values to the test log
  Log.Message(str(FileInfo.DateCreated))
  Log.Message(str(FileInfo.DateLastAccessed))
  Log.Message(str(FileInfo.DateLastModified))

VBScript

Sub SetTimeExample

  sPath = "C:\MyFiles\FileName.txt"

  ' Obtains information about the file
  FileInfo = aqFileSystem.GetFileInfo(sPath)

  ' Specifies a new date of creation, last access and last modification
  CrtDate = aqDateTime.SetDateTimeElements(2010, 06, 30, 15, 24, 32)
  AccDate = aqDateTime.SetDateTimeElements(2010, 07, 02, 10, 54, 03)
  WrtDate = aqDateTime.SetDateTimeElements(2010, 07, 10, 11, 41, 53)
  
  ' Creates a file
  Call aqFile.Create(sPath)
  
  ' Sets a new time when the file was created, last accessed and modified
  Call FileInfo.SetCreationTime(CrtDate)
  Call FileInfo.SetLastAccessTime(AccDate)
  Call FileInfo.SetLastWriteTime(WrtDate)
  
  ' Posts the specified time values to the test log
  Call Log.Message( FileInfo.GetCreationTime )
  Call Log.Message( FileInfo.GetLastAccessTime )
  Call Log.Message( FileInfo.GetLastWriteTime )

End Sub

DelphiScript

function SetTimeExample;
 var sPath, FileInfo, CrtDate, AccDate, WrtDate;

begin

  sPath := 'C:\MyFiles\FileName.txt';

  // Obtains information about the file
  FileInfo := aqFileSystem.GetFileInfo(sPath);

  // Specifies a new date of creation, last access and last modification
  CrtDate := aqDateTime.SetDateTimeElements(2010, 06, 30, 15, 24, 32);
  AccDate := aqDateTime.SetDateTimeElements(2010, 07, 02, 10, 54, 03);
  WrtDate := aqDateTime.SetDateTimeElements(2010, 07, 10, 11, 41, 53);
  
  // Creates a file
  aqFile.Create(sPath);
  
  // Sets a new time when the file was created, last accessed and modified
  FileInfo.SetCreationTime(CrtDate);
  FileInfo.SetLastAccessTime(AccDate);
  FileInfo.SetLastWriteTime(WrtDate);
  
  // Posts the specified time values to the test log
  Log.Message(FileInfo.GetCreationTime);
  Log.Message(FileInfo.GetLastAccessTime);
  Log.Message(FileInfo.GetLastWriteTime);

end;

C++Script, C#Script

function SetTimeExample()
{
  sPath = "C:\\MyFiles\\FileName.txt";

  // Obtains information about the file
  FileInfo = aqFileSystem["GetFileInfo"](sPath);

  // Specifies a new date of creation, last access and last modification
  CrtDate = aqDateTime["SetDateTimeElements"]( 2010, 06, 30, 15, 24, 32 );
  AccDate = aqDateTime["SetDateTimeElements"]( 2010, 07, 02, 10, 54, 03 );
  WrtDate = aqDateTime["SetDateTimeElements"]( 2010, 07, 10, 11, 41, 53 );
  
  // Creates a file
  aqFile["Create"](sPath);
  
  // Sets a new time when the file was created, last accessed and modified
  FileInfo["SetCreationTime"]( CrtDAte );
  FileInfo["SetLastAccessTime"]( AccDate );
  FileInfo["SetLastWriteTime"]( WrtDate );
  
  // Posts the specified time values to the test log
  Log["Message"]( FileInfo["GetCreationTime"] );
  Log["Message"]( FileInfo["GetLastAccessTime"] );
  Log["Message"]( FileInfo["GetLastWriteTime"] );
}

See Also

Working With Files From Scripts
SetCreationTime Method
SetLastWriteTime Method
DateLastAccessed Property

Highlight search results