Skip to content
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.Flowcharts is retired. Current docs
Get Free Trial
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.

File Manipulation APIs

Modes BrowserWindowsJavaAndroidiOSSAP

Reads the file and returns a string.

Parameters

NameTypeDescription
$filePathstringFile path of file to be read as text. File path is resolved relative to files folder of the current project.
$encodingstringoptionalEncodes the data in file. Defaults to "UTF-8"

Returns

stringContent of the file
Raw script
var $contents = _readFile("users.txt");

Sahi Pro Classic API _readFile

Modes BrowserWindowsJavaAndroidiOSSAP

Parameters

NameTypeDescription
$stringstringString to write to file.
$filePathstringFile path of file to write into. File path is resolved relative to files folder of the current project.
$overwritebooleanoptionalIf true, overwrites content. Default is false, which appends at the end of existing content.
$encodingstringoptionalEncoding to be used while writing. Default is "UTF-8"
Raw script
_writeFile("First Line", "out.txt", true); // overwrites content in file
_writeFile("Second Line", "out.txt"); // appends second line in file

Sahi Pro Classic API _writeFile

Modes BrowserWindowsJavaAndroidiOSSAP

This action is the same as _writeFile. Only the name is different.

Parameters

NameTypeDescription
$stringstringString to write to file.
$filePathstringFile path of file to write into. File path is resolved relative to files folder of the current project.
$overwritebooleanoptionalIf true, overwrites content. Default is false, which appends at the end of existing content.
$encodingstringoptionalEncoding to be used while writing. Default is "UTF-8"

Sahi Pro Classic API _writeToFile

Modes BrowserWindowsJavaAndroidiOSSAP

Parameters

NameTypeDescription
$filePathstringFile path of file to delete. File path is resolved relative to files folder of the current project.

Returns

booleantrue if the file was deleted on the filesystem, else false
Raw script
_deleteFile("out.txt"); // deletes out.txt

Sahi Pro Classic API _deleteFile

Modes BrowserWindowsJavaAndroidiOSSAP

Parameters

NameTypeDescription
$filePathstringFile path of file to check. File path is resolved relative to files folder of the current project.

Returns

booleantrue if the file exists on the filesystem, else false
Raw script
_fileExists("out.txt"); // returns true if out.txt exists.

Sahi Pro Classic API _fileExists

Modes BrowserWindowsJavaAndroidiOSSAP

Renames or moves a file from oldFilePath to newFilePath

Parameters

NameTypeDescription
$oldFilePathstringFile path of file to rename. File path is resolved relative to files folder of the current project.
$newFilePathstringNew path of file to write into. File path is resolved relative to files folder of the current project.

Returns

booleantrue if the file was renamed on the filesystem, else false
Raw script
_renameFile("original.txt", "renamed.txt"); // renames original.txt to renamed.txt
_renameFile("original.txt", "newPath/renamed.txt"); // moves and renames original.txt to newPath/renamed.txt

Sahi Pro Classic API _renameFile

Modes BrowserWindowsJavaAndroidiOSSAP

copy a file from srcFilePath to destFilePath

Parameters

NameTypeDescription
$srcFilePathstringFile path of an existing file to copy, must not be null. File path is resolved relative to files folder of the current project.
$destFilePathstringFile path of the new file, must not be null. File path is resolved relative to files folder of the current project.
Raw script
_copyFile("source.txt", "dest.txt"); // copies the source.txt into dest.txt

Sahi Pro Classic API _copyFile

CSV Files are a convenient way to store data. Being text based, they can be easily version controlled and diffed. Sahi has APIs to read and write to CSV Files.

Modes BrowserWindowsJavaAndroidiOSSAP

Given a userinfo.csv file with data

Parameters

NameTypeDescription
$filePathstringfile path to csv file. File path is resolved relative to files folder of the current project.
$propsobjectoptionalProperties to specify for:
wordSeparator: string: Word separator character. Defaults to comma.
ignoreEmptyRows: boolean: Ignores the empty lines. Defaults to false.
includeHeader: boolean: If true, returns the header row also as the first row. Defaults to false.
encoding: string: Encodes the data in csv file. Defaults to "UTF-8".

Returns

two dimensional array of stringsa 2 dimensional array of all values in the csv file
Raw script
1,Ram,18,Male
2,Sam,20,Male

Sahi Pro Classic API _readCSVFile

Modes BrowserWindowsJavaAndroidiOSSAP

Writes the 2 dimensional array into the csv file.

Parameters

NameTypeDescription
$array2d2 dimensional arrayTwo dimensional array of data.
$filePathstringFile path of csv file to write to. File path is resolved relative to files folder of the current project.
$overwritebooleanoptionalIf true, overwrites data. Default is false, which appends data.
$wordSeparatorstringoptionalWord separator character. Defaults to comma.
$forceQuotesbooleanoptionalForce strings to be inside quotes in the csv file. Defaults to true.
$padEmptyCellsbooleanoptionalEmpty cells at the end of rows are not trimmed. Ensures an equal number of commas (separators) in each line. Defaults to false.
Raw script
var $data = [];
$data[0] = ["1", "Ram", 18, "Male"];
$data[1] = ["2", "Sam", 20];
_writeCSVFile($data, "data/userinfo.csv", false, ",", true, true);
//forces data to be inside quotes with specified word separator and empty cells at the end of rows are not trimmed.
//appends data into userinfo.csv.
var $moreData = [["3", "Lak", 30, "Male","Married"]];
_writeCSVFile($moreData, "data/userinfo.csv", false, ",", true, true);

Sahi Pro Classic API _writeCSVFile