aqFile.GetSize Method

Applies to TestComplete 14.70, last modified on April 22, 2021

Description

Use the GetSize method to determine the amount of disk space the specified file occupies.

Declaration

aqFile.GetSize(PathToFile)

PathToFile [in]    Required    String    
Result Double

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

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);
 
 if (aqFile.Exists(sPath))
 {
  // Posts the file's size to the test log
  Log.Message(aqFile.GetSize(sPath));
 }
 else
 {
  Log.Error("The file does not exist.")
 }
 
 // Deletes the file
 aqFile.Delete(sPath);
}

Python

def GetFileSize():
  sPath = "C:\\MyFiles\\FileName.txt"
  # Creates a file
  aqFile.Create(sPath)
  if aqFile.Exists(sPath):
    # Posts the file's size to the test log
    Log.Message(aqFile.GetSize(sPath))
  else:
    Log.Error("The file does not exist.")
  # Deletes the file
  aqFile.Delete(sPath)

VBScript

Sub GetFileSize
 sPath = "C:\MyFiles\FileName.txt"
 
 ' Creates a file
 Call aqFile.Create(sPath)
 
 If (aqFile.Exists(sPath)) Then
  ' Posts the file's size to the test log
  Call Log.Message(aqFile.GetSize(sPath))
 Else
  Call Log.Error("The file does not exist.")
 End If 
 
 ' Deletes the file
 Call aqFile.Delete(sPath)
End Sub

DelphiScript

function GetFileSize;
var sPath;
begin
 sPath := 'C:\MyFiles\FileName.txt';
 
 // Creates a file
 aqFile.Create(sPath);
 
 if (aqFile.Exists(sPath)) then
   // Posts the file's size to the test log
  Log.Message(aqFile.GetSize(sPath))
 else
  Log.Error('The file does not exist.');
 
 // Deletes the file
 aqFile.Delete(sPath);
end;

C++Script, C#Script

function GetFileSize()
{
 var sPath = "C:\MyFiles\FileName.txt";
 
 // Creates a file
 aqFile["Create"](sPath);
 
 if (aqFile["Exists"](sPath))
 {
  // Posts the file's size to the test log
  Log["Message"]( aqFile["GetSize"](sPath) );
 }
 else
 {
  Log["Error"]("The file does not exist.")
 }
 
 // Deletes the file
 aqFile["Delete"](sPath);
}

See Also

Working With Files From Scripts
Size Property
Size Property

Highlight search results