Size Property

Applies to TestComplete 14.92, last modified on September 16, 2021

Description

The Size property returns the size of the file to which the given aqFileInfoObj object corresponds.

Declaration

aqFileInfoObj.Size

Read-Only Property Double
aqFileInfoObj An expression, variable or parameter that specifies a reference to an aqFileInfo object

Applies To

The property is applied to the following object:

Property Value

The file size in bytes.

Example

The code below demonstrates how you can obtain the size of the desired file directly from your script.

JavaScript, JScript

function GetFileSize()
{
 var sPath = "C:\\MyFiles\\FileName.txt";
 
 // Creates a file
 aqFile.Create(sPath);
 
 // Obtains information about the file
 var FileInfo = aqFileSystem.GetFileInfo(sPath);

 // Writes data to the file
 FileInfo.WriteToTextFile("Hello, World!!", aqFile.ctANSI);

 if (FileInfo.Exists)
 {
  // Posts the file's size to the test log
  Log.Message(FileInfo.Size);
 }
 else
 {
  Log.Error("The file does not exist.")
 }
 
 // Deletes the file
 FileInfo.Delete();
}

Python

def GetFileSize():
  sPath = "C:\\MyFiles\\FileName.txt"
  # Creates a file
  aqFile.Create(sPath)
  # Obtains information about the file
  FileInfo = aqFileSystem.GetFileInfo(sPath)
  # Writes data to the file
  FileInfo.WriteToTextFile("Hello, World!!", aqFile.ctANSI)
  if FileInfo.Exists:
    # Posts the file's size to the test log
    Log.Message(FileInfo.Size)
  else:
    Log.Error("The file does not exist.")
  # Deletes the file
  FileInfo.Delete()

VBScript

Sub GetFileSize
 sPath = "C:\MyFiles\FileName.txt"
 
 ' Creates a file
 Call aqFile.Create(sPath)
 
 ' Obtains information about the file
 Set FileInfo = aqFileSystem.GetFileInfo(sPath)

 ' Writes data to the file
 FileInfo.WriteToTextFile "Hello, World!", aqFile.ctANSI

 If (FileInfo.Exists) Then
  ' Posts the file's size to the test log
  Call Log.Message(FileInfo.Size)
 Else
  Call Log.Error("The file does not exist.")
 End If
 
 ' Deletes the file
 Call FileInfo.Delete()
End Sub

DelphiScript

function GetFileSize;
var sPath, FileInfo;
begin
 sPath := 'C:\MyFiles\FileName.txt';
 
 // Creates a file
 aqFile.Create(sPath);

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

 // Writes data to the file
 FileInfo.WriteToTextFile('Hello, World!', aqFile.ctANSI);

 if (FileInfo.Exists) then
   // Posts the file's size to the test log
  Log.Message(FileInfo.Size)
 else
  Log.Error('The file does not exist.');
 
 // Deletes the file
 FileInfo.Delete();
end;

C++Script, C#Script

function GetFileSize()
{
 var sPath = "C:\MyFiles\FileName.txt";
 
 // Creates a file
 aqFile["Create"](sPath);
 
 // Obtains information about the file
 var FileInfo = aqFileSystem["GetFileInfo"](sPath);

 // Writes data to the file
 FileInfo["WriteToTextFile"]("Hello, World!!", aqFile.ctANSI);

 if (FileInfo["Exists"])
 {
  // Posts the file's size to the test log
  Log["Message"]( FileInfo["Size"] );
 }
 else
 {
  Log["Error"]("The file does not exist.")
 }
 
 // Deletes the file
 FileInfo["Delete"]();
}

See Also

Working With Files From Scripts
GetFileInfo Method
Name Property
Path Property

Highlight search results