File¶
File object. Use it to perform actions not related to a particular object. You do not need to record or learn this object, it is always automatically available in any test.
Action Summary¶
Action | Description |
---|---|
Append | Appends text to a file. |
Copy | Copy file srcFileName to dstFileOrFolder . |
CreateFolder | Creates a folder. |
Delete | Deletes a file. |
DeleteFolder | Deletes a folder. |
Exists | Checks if file exists or not. |
Find | Find files in folder using wildcard pattern (including * and ?). |
FolderExists | Checks if folder exists. |
FolderInfo | Gets information about a folder. |
Include | Includes code from a file. |
IncludeOnce | Includes code from a file if it was not included earlier. |
Info | Gets information about a file. |
Read | Reads UTF-8 encoded text file. |
ResolvePath | Finds the file in test folders and calculates its absolute path. |
Touch | Sets file modification time to current time. |
Write | Writes text file. |
Action Detail¶
Append¶
Appends text to a file.
File.Append(fileName, text)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to append text. |
text | string | Text to append to the file. |
Copy¶
Copy file srcFileName
to dstFileOrFolder
. If destination file exists, it gets overwritten. Requires Rapise 8.0+.
File.Copy(srcFileName, dstFileOrFolder)
Parameters:
Name | Type | Description |
---|---|---|
srcFileName | string | Character string file specification, which can include wildcard characters, for one or more files to be copied. |
dstFileOrFolder | string | Character string destination where the file or files from source are to be copied. Wildcard characters are not allowed. |
Returns:
true if succeeded, false otherwise.
CreateFolder¶
Creates a folder.
File.CreateFolder(folderPath)
Parameters:
Name | Type | Description |
---|---|---|
folderPath | string | Path to a folder. |
Delete¶
Deletes a file.
File.Delete(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to delete. |
DeleteFolder¶
Deletes a folder.
File.DeleteFolder(folderPath)
Parameters:
Name | Type | Description |
---|---|---|
folderPath | string | Path to a folder. |
Exists¶
Checks if file exists or not.
File.Exists(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to check. |
Returns:
true if file exists, false otherwise.
Find¶
Find files in folder using wildcard pattern (including * and ?).
I.e. File.Find("c:/Temp", "*.txt", true) may return C:\Temp\file1.txt C:\Temp\SubFolder\file2.txt C:\Temp\SubFolder2\file3.txt C:\Temp\SubFolder2\file4.txt Result may be converted to array like that: var arrFiles = File.Find("c:/Temp", "*.txt", true).split('\n');
File.Find(path, searchPattern, recursive, firstOnly, files, folders)
Parameters:
Name | Type | Description |
---|---|---|
path | string | Path to a folder to search in. |
searchPattern | string | Search pattern (may include * and ? wildcards, but no regexp). |
recursive | boolean | 'true' for folder and subfolders. Optional, Default: "false". |
firstOnly | boolean | Return only first matching item (if any). Optional, Default: "false". |
files | boolean | Return matching files. Optional, Default: "true". |
folders | boolean | Return matching folders. Optional, Default: "false". |
Returns:
string: \n-separated string where each line is a path to the found item.
FolderExists¶
Checks if folder exists.
File.FolderExists(folderPath)
Parameters:
Name | Type | Description |
---|---|---|
folderPath | string | Path to a folder. |
Returns:
true if folder exists, false - otherwise.
FolderInfo¶
Gets information about a folder.
File.FolderInfo(folderPath)
Parameters:
Name | Type | Description |
---|---|---|
folderPath | string | Path to a folder. |
Returns:
Folder object as described here https://msdn.microsoft.com/en-us/library/1c87day3%28v=vs.84%29.aspx e.g. Path, SubFolders and Files enumeration.
Include¶
Includes code from a file.
Normally used together with eval statement, i.e.:
eval( File.Include('myfile.js') )
File.Include(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to load. |
Returns:
Contents of the source file for evaluation.
IncludeOnce¶
Includes code from a file if it was not included earlier.
Normally used together with eval statement, i.e.:
eval( File.IncludeOnce('myfile.js') )
File.IncludeOnce(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to load. |
Returns:
Contents of the source file for evaluation.
Info¶
Gets information about a file.
File.Info(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file. |
Returns:
File object as described here https://msdn.microsoft.com/en-us/library/1ft05taf%28v=vs.84%29.aspx e.g. DateLastModified, Size, Type, Name, Path.
Read¶
Reads UTF-8 encoded text file.
File.Read(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to read. |
Returns:
Contents of the text file as string.
ResolvePath¶
Finds the file in test folders and calculates its absolute path.
File.ResolvePath(fileName, relTo)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to resolve path. |
relTo | string | Resolve path relative to a given File or Dir. Optional. |
Returns:
Absolute path of the file.
Touch¶
Sets file modification time to current time.
File.Touch(fileName)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to touch. |
Write¶
Writes text file.
File.Write(fileName, text)
Parameters:
Name | Type | Description |
---|---|---|
fileName | string | Name of the file to write. |
text | string | Text to write into the file. |