File and Folder References
SenseTalk provides several methods for working with files and file systems. You can use the commands and functions described here to access files and file system information, to determine or change your working directory, and other details about paths and directories. You can also access properties for individual files, such as file size and assigned permissions.
SenseTalk commands and functions for working with files and file system objects operate on the local machine rather than on a system under test (SUT).
The examples below show you how to access file and file system information by using SenseTalk. For topics such as creating or deleting files, writing to files, and other ways of altering files or file system objects, see File and Folder Interaction.
As a best practice, any files referenced within a SenseTalk script should be added to Eggplant Functional through the Resources pane in the Suite window. This method stores files to the Resources directory within the suite directory for the given suite. Although SenseTalk can access files stored elsewhere on the local file system, using the Resources directory provides additional capabilities. See the Resources Pane for more information.
Referring to Files in a Script
File
, Folder
Expression
To refer to a file in a script, just use the word file
followed by an expression that evaluates to the name of the file. You can refer to folders in a similar way, using the word folder
instead of file
.
Syntax:
file filePath
folder filePath
directory filePath
The words folder
and directory
are used interchangeably within SenseTalk scripts—wherever the word folder
is used in a script, you can use the word directory
instead.
The filePath can be the text of a path in either Mac/Linux or Windows format, or it can be a list in which each item is one component of the path.
The name given can be either the full (absolute) path name of the file or folder, or the path relative to the current working folder (see the folder
global property). SenseTalk determines the full “absolute” path name of the file based on the name given, according to the following rules:
- if the name begins with a slash (/) or the first item in the path list is "/" it is already an absolute file name
- if the name begins with a drive letter and colon followed by a slash or backslash (like "C:\") or the first item in the path list is a drive letter and colon and the second item is a slash it is already an absolute file name
- if the name begins with a tilde and a slash (~/) it represents a path relative to the user’s home folder
- if the name begins with a tilde (~) followed by a user name it represents a path relative to that specific user’s home folder
- if the name begins with a period and a slash (./) or two periods and a slash (../) it represents a relative path from either the current working folder or the current working folder's parent folder, respectively
- otherwise, it represents a file or path within the current working folder (
the folder
global property)
File paths on Mac and Linux systems and on the web use the slash character /
to separate path components, but Windows systems use the backslash character \
instead. SenseTalk accepts file paths in either format interchangeably (as well as lists of path components), but defaults to using slash /
when representing paths. You may use the FilePath
or WindowsFilePath
functions if you need a platform-specific standard representation.
Example:
open file"/etc/passwd"
move file "runlog24" into folder "archivedLogs"