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.

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.

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.

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.

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.

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.

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.

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.

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.

readText

Signature: (path: text) -> text.

Read the text content from the specified file. Reading too large files can cause performance issues.

readLines

Signature: (path: text) -> text*.

Read all lines from a file as sequence of texts/table. Reading too large files can cause performance issues.

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.

fileExists

Signature: (path: text) -> boolean

Determines whether a file exists at the specified path.

deleteFile

Signature: (path: text) -> boolean

Deletes the file at provided path.

copyFile

Signature: (source: text, destination: text, options: FileSystem.OverwriteOptions) -> boolean

Copies a file from a source location to a destination location.

moveFile

Signature: (source: text, destination: text, options: FileSystem.OverwriteOptions) -> boolean

Moves a file from a source location to destination location.

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.

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.

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.

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.

triangle-exclamation

  • html: text - Defines the HTML content to be used. The operation only supports HTML 4.01 specificationarrow-up-right

  • css: text - Defines the CSS content for the HTML. The operation only supports the CSS Level 2 Specificationarrow-up-right

  • 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 or portrait

    Example page layouts:

    1. A4 page size with portrait

    2. Manual page size

  • 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:

Output: FileSystem.ReadBinaryRecord { filename: text, data: binary }

Handling Tables

To iterator over a table and print values for each row you can use flowscript map operation. Following example depicts an instance where we loop through a table named fileData (containing columns filename & data)

mergePdfs

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.

Last updated

Was this helpful?