aqFile.SetLastWriteTime Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the SetLastWriteTime method to set a new date and/or time of the last modification of the specified file. To read the current date and time of the last modification, call the GetLastWriteTime method.

Declaration

aqFile.SetLastWriteTime(Path, Time)

Path [in]    Required    String    
Time [in]    Required    Date/Time    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Path

Specifies the fully-qualified path to the desired file.

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";
  
  // Creates a file
  aqFile.Create(sPath);
  
  // Sets new time when the file was created, last accessed and modified
  aqFile.SetCreationTime(sPath, aqDateTime.SetDateTimeElements(2010, 06, 30, 15, 24, 32));
  aqFile.SetLastAccessTime(sPath, aqDateTime.SetDateTimeElements(2010, 07, 02, 10, 54, 03));
  aqFile.SetLastWriteTime(sPath, aqDateTime.SetDateTimeElements(2010, 07, 10, 11, 41, 53));
  
  // Posts specified time values to the test log
  Log.Message(aqFile.GetCreationTime(sPath));
  Log.Message(aqFile.GetLastAccessTime(sPath));
  Log.Message(aqFile.GetLastWriteTime(sPath));
}

Python

def SetTimeExample():
  sPath = "C:\\MyFiles\\FileName.txt"
  # Creates a file
  aqFile.Create(sPath)
  # Sets new time when the file was created, last accessed and modified
  aqFile.SetCreationTime(sPath, aqDateTime.SetDateTimeElements(2010, 6, 30, 15, 24, 32))
  aqFile.SetLastAccessTime(sPath, aqDateTime.SetDateTimeElements(2010, 7, 2, 10, 54, 3))
  aqFile.SetLastWriteTime(sPath, aqDateTime.SetDateTimeElements(2010, 7, 10, 11, 41, 53))
  # Posts specified time values to the test log
  Log.Message(aqFile.GetCreationTime(sPath))
  Log.Message(aqFile.GetLastAccessTime(sPath))
  Log.Message(aqFile.GetLastWriteTime(sPath))

VBScript

Sub SetTimeExample

  sPath = "C:\MyFiles\FileName.txt"
  
  ' Creates a file
  Call aqFile.Create(sPath)
  
  ' Sets new time when the file was created, last accessed and modified
  Call aqFile.SetCreationTime(sPath, aqDateTime.SetDateTimeElements(2010, 06, 30, 15, 24, 32))
  Call aqFile.SetLastAccessTime(sPath, aqDateTime.SetDateTimeElements(2010, 07, 02, 10, 54, 03))
  Call aqFile.SetLastWriteTime(sPath, aqDateTime.SetDateTimeElements(2010, 07, 10, 11, 41, 53))
  
  ' Posts specified time values to the test log
  Call Log.Message(aqFile.GetCreationTime(sPath))
  Call Log.Message(aqFile.GetLastAccessTime(sPath))
  Call Log.Message(aqFile.GetLastWriteTime(sPath))

End Sub

DelphiScript

function SetTimeExample;
 var sPath;

begin

  sPath := 'C:\MyFiles\FileName.txt';
  
  // Creates a file
  aqFile.Create(sPath);
  
  // Sets new time when the file was created, last accessed and modified
  aqFile.SetCreationTime(sPath, aqDateTime.SetDateTimeElements(2010, 06, 30, 15, 24, 32));
  aqFile.SetLastAccessTime(sPath, aqDateTime.SetDateTimeElements(2010, 07, 02, 10, 54, 03));
  aqFile.SetLastWriteTime(sPath, aqDateTime.SetDateTimeElements(2010, 07, 10, 11, 41, 53));
  
  // Posts specified time values to the test log
  Log.Message(aqFile.GetCreationTime(sPath));
  Log.Message(aqFile.GetLastAccessTime(sPath));
  Log.Message(aqFile.GetLastWriteTime(sPath));

end;

C++Script, C#Script

function SetTimeExample()
{
  sPath = "C:\\MyFiles\\FileName.txt";
  
  // Creates a file
  aqFile["Create"](sPath);
  
  // Sets new time when the file was created, last accessed and modified
  aqFile["SetCreationTime"]( sPath, aqDateTime["SetDateTimeElements"]( 2010, 06, 30, 15, 24, 32 ) );
  aqFile["SetLastAccessTime"]( sPath, aqDateTime["SetDateTimeElements"]( 2010, 07, 02, 10, 54, 03 ) );
  aqFile["SetLastWriteTime"]( sPath, aqDateTime["SetDateTimeElements"]( 2010, 07, 10, 11, 41, 53 ) );
  
  // Posts specified time values to the test log
  Log["Message"]( aqFile["GetCreationTime"](sPath) );
  Log["Message"]( aqFile["GetLastAccessTime"](sPath) );
  Log["Message"]( aqFile["GetLastWriteTime"](sPath) );
}

See Also

Working With Files From Scripts
SetCreationTime Method
SetLastAccessTime Method
GetLastWriteTime Method
DateLastModified Property

Highlight search results