SaveAs Method

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

Use the SaveAs method to save options to the file specified by FileName. The specified file is different from the file for which the FileSection object was created. This means it is not the file you specified in the XML, INI or Binary method of the Storages object. If the file does not exist, SaveAs creates it. If you do not call the Save or SaveAs method of the FileSection object, all changes will be lost.

Declaration

FileSectionObj.SaveAs(FileName)

FileSectionObj An expression, variable or parameter that specifies a reference to a FileSection object
FileName [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

FileName

Specifies the full path to the desired file.

Result Value

None.

Example

The code below obtains a binary file, makes some changes to the options stored in the file and then saves the file under a different name.

JavaScript, JScript

function FileSectionExample()
{
  // Obtains the file to get access to
  var sFile = Storages.Binary("C:\\Work\\OptionsFile.txt");
  // Obtains the total number of options stored in the file
  var OptNum = sFile.OptionCount;
  
  // Iterates through the options
  for (var i = 0; i < OptNum; i++)
    // Makes some changes to the current option
    sFile.SetOptionByIndex(i, "...");
  
  // Saves the file
  sFile.SaveAs("D:\\MyFiles\\NewOptions.txt");
   
}

Python

def FileSectionExample():
  # Obtains the file to get access to
  sFile = Storages.Binary("C:\\Work\\OptionsFile.txt")
  # Obtains the total number of options stored in the file
  OptNum = sFile.OptionCount
  # Iterates through the options
  for i in range(0, OptNum):
    # Makes some changes to the current option
    sFile.SetOptionByIndex[i, "..."]
  # Saves the file 
  sFile.SaveAs("D:\\MyFiles\\NewOptions.txt")

VBScript

Sub FileSectionExample

  ' Obtains the file to get access to
  Set sFile = Storages.Binary("C:\Work\OptionsFile.txt")
  ' Obtains the total number of options stored in the file
  OptNum = sFile.OptionCount
  
  ' Iterates through the options
  For i = 0 to (OptNum - 1)
    ' Makes some changes to the current option
    Call sFile.SetOptionByIndex(i, "...")
  Next
  
  ' Saves the file
  sFile.SaveAs("D:\MyFiles\NewOptions.txt")
   
End Sub

DelphiScript

function FileSectionExample;
var sFile, OptNum, i;
begin

  // Obtains the file to get access to
  sFile := Storages.Binary('C:\Work\OptionsFile.txt');
  // Obtains the total number of options stored in the file
  OptNum := sFile.OptionCount;
  
  // Iterates through the options
  for i := 0 to (OptNum - 1) do
    // Makes some changes to the current option
    sFile.SetOptionByIndex(i, '...');
  
  // Saves the file
  sFile.SaveAs('D:\MyFiles\NewOptions.txt');
   
end;

C++Script, C#Script

function FileSectionExample()
{
  // Obtains the file to get access to
  var sFile = Storages["Binary"]( "C:\\Work\\OptionsFile.txt" );
  // Obtains the total number of options stored in the file
  var OptNum = sFile["OptionCount"];
  
  // Iterates through the options
  for (var i = 0; i < OptNum; i++)
    // Makes some changes to the current option
    sFile["SetOptionByIndex"]( i, "..." );
  
  // Saves the file
  sFile["SaveAs"]( "D:\\MyFiles\\NewOptions.txt" );
   
}

See Also

FileSection.Save
Storages Object
Storages.Binary
Storages.INI
Storages.XML

Highlight search results