FileSystem Module
The FileSystem module allows interaction with directories and files on both local and network file systems.
FileSystem module functions
directoryExists
Signature: (path: text) -> boolean.
Determines whether a directory exists at the specified path.
Output: Returns True if the directory exists, False otherwise.
//path to the directory
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory";
return FileSystem.directoryExists(path);
//The path parameter can be passed as inline value as well.
return FileSystem.directoryExists(@"D:\testDirectory");
createDirectory
Signature: (path: text) -> text.
Creates all directories at the specified path. This operation does not duplicate existing directories. An error will be thrown if the path contains invalid characters.
Output: Returns the path of the newly created directory.
// path & name of the directory that should be created.
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory\subDirectory";
let createdFilePath = FileSystem.createDirectory(path);
//The path parameter can be passed as inline value as well.
let createdFilePath = FileSystem.createDirectory(@"D:\testDirectory\subDirectory");
deleteDirectory
Signature: (path: text, options: FileSystem.DeleteSubdirectoriesOptions) -> boolean.
Deletes the directory at the specified path. The directory must be empty unless DeleteSubdirectoriesOptions
is set to true, in which case all subdirectories and files within it will also be deleted.
Output: Returns true if directory deletion was successful, false otherwise.
// path & name of the directory that should be deleted.
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory";
return FileSystem.deleteDirectory(path, {deleteSubdirectories: true});
getDirectories
Signature: (path: text, options: FileSystem.SearchOptions) -> text*.
Returns the full path of all subdirectories under a given directory.
Optional parameter SearchOptions
has two properties.
pattern: text - Optional filter to match directory names using wildcards (
*
and?
). Regular expressions are not supported.recursive: boolean - indicates whether to include nested subdirectories recursively. Default is false.
Output: Returns the full path of all subdirectories under the given directory.
// path to the directory.
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory";
//Returns full path of all subdirectories under testDirectory.
let subDirectories1 = FileSystem.getDirectories(path);
//Returns the full paths of all subdirectories that start with 'Test' directly under testDirectory.
let subDirectories2 = FileSystem.getDirectories(path, {pattern: 'Test*'});
//Returns the full paths of all subdirectories that start with 'Test' either directly under testDirectory or within any of its subdirectories.
let subDirectories3 = FileSystem.getDirectories(path, {pattern: 'Test*',recursive: true});
getSubDirectoryNames
Signature: (path: text, options: FileSystem.SearchOptions) -> text*.
Returns the names of all subdirectories under a given directory.
Optional parameter SearchOptions
has two properties.
pattern: text - Optional filter to match directory names using wildcards (
*
and?
). Regular expressions are not supported.recursive: boolean - indicates whether to include nested subdirectories recursively. Default is false.
Output: Returns the full path of all subdirectories under the given directory.
// path to the directory.
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory";
return FileSystem.getSubDirectoryNames(path)
getFiles
Signature: (path: text, options: FileSystem.SearchOptions) -> text*.
Returns the full path of all files under a given directory.
Optional parameter SearchOptions
has two properties.
pattern: text - Optional filter to match file names using wildcards (
*
and?
). Regular expressions are not supported.recursive: boolean - indicates whether to include files inside subdirectories recursively. Default is false.
Output: Returns the full path of all files under the given directory.
// path to the directory.
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory";
//Returns full path of all files under testDirectory.
let allFiles = FileSystem.getFiles(path);
//Returns the full paths of all files that start with 'Test' directly under testDirectory.
let filesStartsWithTest = FileSystem.getFiles(path, {pattern: 'Test*'});
//Returns the full paths of all files that start with 'Test' either directly under testDirectory or within any of its subdirectories.
let filesStartsWithTest2 = FileSystem.getFiles(path, {pattern: 'Test*',recursive: true})
getFileNames
Signature: (path: text, options: FileSystem.SearchPatternOptions) -> text*.
Returns the names (including extension) of all files in given directory.
Optional parameter SearchPatternOptions
can be used to filter matching file names using wildcards (*
and ?
). Regular expressions are not supported.
Output: Returns the names (including extension) of all files under the given directory.
// path to the directory.
//it is recommended to use @ to prevent potential errors caused by unescaped backslashes
let path = @"D:\testDirectory";
//Returns name of all files under testDirectory.
let allFiles = FileSystem.getFileNames(path);
//Returns name of all files that start with 'Test' directly under testDirectory.
let filesStartsWithTest = FileSystem.getFileNames(path, {pattern: 'Test*'});
writeText
Signature: (path: text, content: text | text* , options: FileSystem.WriteFileOptions)
Writes the specified text or sequence of texts to a file within an existing directory. Optional parameter WriteFileOptions
has two properties.
encoding: text - Defines the text encoding to use when writing the file. Supported encoding types are:
UTF-8 - Default if no encoding type is specified.
UTF-16
UTF-32
ASCII
ISO-8859-1
WINDOWS-1252
overwriteIfExist: boolean - Specifies whether to replace an existing file with the same name.
let file1 = @"D:\testDirectory\subDirectory\TextContent.txt";
let file2 = @"D:\testDirectory\subDirectory\SequenceContent.txt";
let textContent = "This is a sample text content";
let sequenceContent = ["text line 1", "text line 2", "text line 3"];
//Writing text content to a file &
//use encoidng UTF-8 & overwrite if there is a file with same name already exists
Do FileSystem.writeText(file1 , textContent, {encoding: "UTF-8", overwriteIfExist: true});
//Writing a table/sequence to a file
Do FileSystem.writeText(file2 , sequenceContent);
appendText
Signature: (path: text, content: text | text*, options: FileSystem.EncodingOptions)
Appends the specified text or sequence of texts to an existing file. The optional options parameter EncodingOptions
defines the text encoding to use when appending the content.
let file1 = @"D:\testDirectory\subDirectory\TextContent.txt";
let file2 = @"D:\testDirectory\subDirectory\SequenceContent.txt";
let textContent = "Appended text content";
let sequenceContent = ["text line 4", "text line 5", "text line 6"];
//Append the text content to the file
Do FileSystem.writeText(file1 , textContent, {encoding: "UTF-8", overwriteIfExist: true});
//Append a table/sequence to a file
Do FileSystem.writeText(file2 , sequenceContent);
writeBinary
Signature: (path: text, content: binary, options: FileSystem.OverwriteOptions)
Writes the binary content to a file within an existing directory. If a file with the given name already exists, the optional options parameter OverwriteOptions
determines whether it should be replaced.
let file3 = @"D:\testDirectory\subDirectory\RandomImage.png";
//randomImageRec holds the binary data from a REST response in the previous script step
let binaryData = randomImageRec.contents;
//Write binary data fetched from a REST response into a file
Do FileSystem.writeBinary(file3, binaryData, {overwriteIfExist: true});
readText
Signature: (path: text) -> text.
Read the text content from the specified file. Reading too large files can cause performance issues.
let filePath = @"D:\testDirectory\subDirectory\TextContent.txt";
//Reading text content from a file
let textContent = FileSystem.readText(filePath);
readLines
Signature: (path: text) -> text*.
Read all lines from a file as sequence of texts/table. Reading too large files can cause performance issues.
let filePath = @"D:\testDirectory\subDirectory\StockRecords.csv";
//Reading csv file into flow as a sequnce/table. Each line in the csv will be a new row
let lines = FileSystem.readLines(filePath);
readBinary
Signature: (path: text) -> FileSystem.ReadBinaryRecord
Reads a file from specified path, returning a FileSystem.ReadBinaryRecord that can easily be used in File Gallery. Reading too large files can cause performance issues.
let filePath = @"D:\testDirectory\subDirectory\SalesPart.png";
//fileRecord will contain two columns, filename & data
let fileRecord = FileSystem.readBinary(filePath);
fileExists
Signature: (path: text) -> boolean
Determines whether a file exists at the specified path.
let filePath = @"D:\testDirectory\subDirectory\Test.txt";
//returns true if the file exists
return FileSystem.fileExists(filePath);
deleteFile
Signature: (path: text) -> boolean
Deletes the file at provided path.
//path to the file to be deleted
let filePath = @"D:\testDirectory\subDirectory\Test.txt";
//returns true if the delete was successfull
return FileSystem.deleteFile(filePath);
copyFile
Signature: (source: text, destination: text, options: FileSystem.OverwriteOptions) -> boolean
Copies a file from a source location to a destination location.
//Copy the source.txt file from source directory to destination directory with the name destination.txt
let source= @"D:\testDirectory\source\source.txt";
let destination= @"D:\testDirectory\destination\destination.txt";
//returns true if the copy operation was successfull
//overwrite if there is a file with same name already exists
return FileSystem.deleteFile(source,destination, {overwriteIfExist: true});
moveFile
Signature: (source: text, destination: text, options: FileSystem.OverwriteOptions) -> boolean
Moves a file from a source location to destination location.
//Move the source.txt file from source directory to destination directory with the name destination.txt
let source= @"D:\testDirectory\source\source.txt";
let destination= @"D:\testDirectory\destination\destination.txt";
//returns true if the move operation was successfull
//overwrite if there is a file with same name already exists
return FileSystem.deleteFile(source,destination, {overwriteIfExist: true});
addFolderToZip
Signature: (source: text, destination: text, options: FileSystem.AddFolderToZipOptions) -> text
Zips all files and subfolders in a folder into a zip file. If a file with the given name already exists, the optional options parameter AddFolderToZipOptions
determines the action to take:
replaceMode: "Always"
- Replace any existing zip files with the same name with the new zip file.replaceMode: "Never"
- Do not replace any existing zip files with the same name.replaceMode: "ReportError"
- Raise an error if a zip file with the same name already exists
Output: Returns the path of the created zip file.
//Create a zip file from the content of source directory to destination directory
let source= @"D:\Filesystem\source\ToZip";
let destination= @"D:\\Filesystem\destination\zipped.zip";
//overwrite if there is a file with same name already exists
return FileSystem.addFolderToZip(source, destination, {replaceMode: "Always"});
extractFromZip
Signature: (source: text, destination: text, options: FileSystem.OverwriteOptions) -> boolean
Extracts all files from a zip file. If a file with the given name already exists, the optional options parameter OverwriteOptions
determines whether it should be replaced.
Output: Returns true if the operation was successful, false otherwise.
//Extract the content of the zip file source/DemoFiles.zip to destination directory DemoFiles
let source= @"D:\Filesystem\source\DemoFiles.zip";
let destination= @"D:\\Filesystem\destination\DemoFiles";
//overwrite if there is a file with same name already exists
return FileSystem.extractFromZip(source, destination, {overwriteIfExist: true});
combinePath
Signature: (path: text*) -> text
Combines two or more path segments into a single, valid file or directory path. Useful for dynamically constructing file system paths in a safe way.
Output: A single, combined path string.
let baseDirectory = @"D:\Filesystem";
let subdirectory = @"code\source\test\TestResult.txt";
//Returns the combined path D:\Filesystem\code\source\test\TestResult.txt
return FileSystem.combinePath([baseDirectory, subdirectory]);
convertHtmlToPdf
Signature: (fileName: text, html: text, options: FileSystem.PdfOptions) -> FileSystem.ReadBinaryRecord
Converts a HTML content into PDF returning a FileSystem.ReadBinaryRecord that can easily be used in File Gallery. The options parameter PdfOptions
has multiple properties that you can use to control different setting of the pdf file.
convertHtmlToPdf operation only supports HTML 4.01 specification and CSS Level 2 Specification
html: text - Defines the HTML content to be used. The operation only supports HTML 4.01 specification
css: text - Defines the CSS content for the HTML. The operation only supports the CSS Level 2 Specification
layout:
pageSize: text - Following standard formats are supported:
ISO A series:
A0
,A1
,A2
,A3
,A4
,A5
ISO RA series:
RA0
,RA1
,RA2
,RA3
,RA4
,RA5
ISO B series:
B0
,B1
,B2
,B3
,B4
,B5
Common/Legacy:
Quarto
,Ledger
,Tabloid
,Post
,Crown
,LargePost
,Demy
,Medium
,Royal
,Elephant
,DoubleDemy
,STMT
,Folio
,Statement
,Size 10x14
Manual: The page size can also be defined manually. In that case you need to define a pageHeight and a pageWidth.
pageOrientation: Can be
landscape
orportrait
Example page layouts:
A4 page size with portrait
layout: { pageSize: "A4", pageOrientation: "portrait" }
Manual page size
layout: { pageSize: "Manual", pageHeight: 150, pageWidth: 80 }
margin: Define the page margins with marginTop, marginBottom, marginLeft, marginRight properties. Default is 72 points (1 inch = 72 points). Zero is allowed but may cause content to render at page edges.
Example:
margin: { marginTop: 72, marginBottom: 72, marginLeft: 72, marginRight: 72 }
Output: FileSystem.ReadBinaryRecord { filename: text, data: binary }
let imageAsBase64 = "data:image/png;base64," & base64Encode(scannedImage.data);
let htmlContent = `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Sample PDF Document</title>
</head>
<body>
<IMG src = "{imageAsBase64}"; style="width:825px;height:577px;" >
</body>
</html>`;
let cssContent = @"container_2{-webkit-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);} .rotate-image{transform:rotate(45deg);margin-top:100px;} table{page-break-inside:avoid;width:100%;font-family:DejaVuSansCondensed;font-size:9pt;line-height:1.2;margin-top:2pt;margin-bottom:5pt;border-collapse:collapse;} thead{font-weight:bold;vertical-align:bottom;} tfoot{font-weight:bold;vertical-align:top;} thead td{font-weight:bold;} tfoot td{font-weight:bold;} thead td,thead th,tfoot td,tfoot th{page-break-inside:avoid;font-variant:small-caps;} th{page-break-inside:avoid;font-weight:bold;vertical-align:top;text-align:left;padding-left:2mm;padding-right:2mm;padding-top:0.5mm;padding-bottom:0.5mm;} td{page-break-inside:avoid;padding-left:2mm;vertical-align:top;text-align:left;padding-right:2mm;padding-top:0.5mm;padding-bottom:0.5mm;} th p{text-align:left;margin:0pt;} td p{text-align:left;margin:0pt;} hr{width:100%;height:1px;text-align:center;color:#999999;margin-top:8pt;margin-bottom:8pt;} a{color:#000066;font-style:normal;text-decoration:underline;font-weight:normal;} ul{text-indent:5mm;margin-bottom:9pt;} ol{text-indent:5mm;margin-bottom:9pt;} pre{font-family:DejaVuSansMono;font-size:9pt;margin-top:5pt;margin-bottom:5pt;} h1{font-weight:normal;font-size:26pt;color:#000066;font-family:DejaVuSansCondensed;margin-top:18pt;margin-bottom:6pt;border-top:0.075cm solid #000000;border-bottom:0.075cm solid_";
let pageLayout = {pageSize: 'A4', pageOrientation: 'portrait'};
let pageMargins = {};
return FileSystem.convertHtmlToPdf("scannedInvoice.pdf",htmlContent, {css: cssContent, layout: pageLayout, margin: pageMargins});
mergeTwoPdfs
Signature: (fileName: text, firstPdf: FileSystem.PdfMergeRecord, secondPdf: FileSystem.PdfMergeRecord) -> FileSystem.ReadBinaryRecord
Merges two PDF files into a single PDF returning a FileSystem.ReadBinaryRecord that can easily be used in File Gallery. Specific pages may be extracted from each PDF before merging, according to optional start and end page parameters inside PdfMergeRecord
.
data: binary- binary representation of the pdf file.
startPage: Optional. First page to include. Default = 0
endPage: Optional. Last page to include.
let firstPdf = FileSystem.readBinary(@"D:\testDirectory\subDirectory\first.pdf");
let secondPdf = FileSystem.readBinary(@"D:\testDirectory\subDirectory\second.pdf");
let firstPDfMergRecord = {data: firstPdf.data, startPage: 2, endPage: 10};
let secondPDfMergRecord = {data: secondPdf.data};
return FileSystem.mergeTwoPdfs("outPDf.pdf", firstPDfMergRecord, secondPDfMergRecord);
Last updated
Was this helpful?