Description
Use the SetCurrentFolder
method to set the folder specified by the DirStr parameter as the current folder. To obtain the path of the current folder, use the GetCurrentFolder
method.
Declaration
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
DirStr
Specifies the fully qualified path to the folder to be set as the current one.
The DirStr parameter may or may not include a trailing backslash (\).
You can add a trailing backslash to or remove it from the path by using the IncludeTrailingBackSlash
or ExcludeTrailingBackSlash
method.
Result Value
If the current folder has been changed successfully, the method returns True. Otherwise, it returns False.
Remarks
If your project contains event handlers, the test engine resets the current folder to the project’s folder every time an event handler runs. You have to set the desired current folder with the SetCurrentFolder
method at the end of the event handling routine.
Example
The code below sets the MyFiles folder as the current folder, specifies the relative path to a file stored in it and then obtains the fully qualified name of the specified file.
JavaScript, JScript
function SetCurFolderExample()
{
// Specifies the current folder location
var sCurFold = "C:\\MyFiles";
// Sets the MyFiles folder as the current folder
aqFileSystem.SetCurrentFolder(sCurFold);
// Specifies the relative path to the file
var sPath = "..\\Work\\TextFile.txt";
// Obtains the fully qualified file name
var sName = aqFileSystem.ExpandFileName(sPath);
// Posts this name to the test log
Log.Message(sName);
}
Python
def SetCurFolderExample():
# Specifies the current folder location
sCurFold = "C:\\MyFiles"
# Sets the MyFiles folder as the current folder
aqFileSystem.SetCurrentFolder(sCurFold)
# Specifies the relative path to the file
sPath = "..\\Work\\TextFile.txt"
# Obtains the fully qualified file name
sName = aqFileSystem.ExpandFileName(sPath)
# Posts this name to the test log
Log.Message(sName)
VBScript
Sub SetCurFolderExample
Dim sCurFold, sPath, sName
' Specifies the current folder location
sCurFold = "C:\MyFiles"
' Sets the MyFiles folder as the current folder
aqFileSystem.SetCurrentFolder(sCurFold)
' Specifies the relative path to the file
sPath = "..\Work\TextFile.txt"
' Obtains the fully qualified file name
sName = aqFileSystem.ExpandFileName(sPath)
' Posts this name to the test log
Log.Message(sName)
End Sub
DelphiScript
function SetCurFolderExample;
var sCurFold, sPath, sName;
begin
// Specifies the current folder location
sCurFold := 'C:\MyFiles';
// Sets the MyFiles folder as the current folder
aqFileSystem.SetCurrentFolder(sCurFold);
// Specifies the relative path to the file
sPath := '..\Work\TextFile.txt';
// Obtains the fully qualified file name
sName := aqFileSystem.ExpandFileName(sPath);
// Posts this name to the test log
Log.Message(sName);
end;
C++Script, C#Script
function SetCurFolderExample()
{
// Specifies the current folder location
var sCurFold = "C:\\MyFiles";
// Sets the MyFiles folder as the current folder
aqFileSystem["SetCurrentFolder"](sCurFold);
// Specifies the relative path to the file
var sPath = "..\\Work\\TextFile.txt";
// Obtains the fully qualified file name
var sName = aqFileSystem["ExpandFileName"](sPath);
// Posts this name to the test log
Log["Message"](sName);
}
See Also
Working With Files From Scripts
GetCurrentFolder Method
DeleteFolder Method
CreateFolder Method