aqFile.SetCreationTime Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Use the SetCreationTime method to set a new date and/or time of file creation. To read the current creation date and time, call the GetCreationTime method.

Declaration

aqFile.SetCreationTime(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
SetLastAccessTime Method
SetLastWriteTime Method
GetCreationTime Method
DateCreated Property

Highlight search results