Skip to content

File Functions

BuildPath

Description

Append a name onto an existing path. The format of the new path is ‘path\name'.

Syntax

BuildPath( path, name)

Arguments

  • path
    • A string representing a file path.
  • name
    • A string of either a subpath or file name.

Example

' Joins a directory and a file name, inserting the
' separator.
BuildPath("C:\IMan\Outbound", %OrderNo & ".csv")
' Returns "C:\IMan\Outbound\SO-10432.csv"

' Through a FileSystem setup, named first. The container
' comes from the setup, so the path is relative to it.
BuildPath("AzureBlob-Archive", "outbound", %OrderNo & ".csv")
' Returns "outbound/SO-10432.csv"

FileExists

Description

Returns whether the file specified by the File argument exists.

Syntax

FileExists( file )

Arguments

  • file
    • The full path of the file.

Example

' Returns False on any error, including a bad path,
' rather than raising.
FileExists("C:\IMan\Inbound\" & %OrderNo & ".xml")   ' Returns True or False

' The guarded read this is normally half of:
Dim f
f = BuildPath("C:\IMan\Inbound", %OrderNo & ".xml")
IIf(FileExists(f), ReadTextFile(f, False), "")

FileName

Description

Returns the file name from a path.

Syntax

FileName( filepath )

Arguments

  • filepath
    • The full path of the file.

Example

' The file portion of a path, extension included.
FileName("C:\IMan\Outbound\SO-10432.csv")   ' Returns "SO-10432.csv"

FilePath

Description

Returns the path from a file path.

Syntax

FilePath( filepath)

Arguments

  • filepath
    • The full path of the file.

Example

' The directory portion of a path -- the complement of
' FileName.
FilePath("C:\IMan\Outbound\SO-10432.csv")   ' Returns "C:\IMan\Outbound"

ReadTextFile

Description

Reads the contents of a text file.

Syntax

ReadTextFile( filepath , throwonerror )

Arguments

  • filepath
    • The full path of the file.
  • throwonerror
    • When set to False the function will return an empty string instead of raising an error when an error occurs either opening or reading the file.

Example

' Reads the whole file as UTF-8. The last argument is
' throwOnError: False returns an empty string for a
' missing or unreadable file and the integration
' continues; True fails the record.
ReadTextFile("C:\IMan\Inbound\" & %OrderNo & ".xml", False)

' Through a FileSystem setup, named first -- here an AWS
' S3 bucket. The bucket comes from the setup, so the path
' is the object key within it.
ReadTextFile("S3-Inbound", "orders/" & %OrderNo & ".xml", True)

WriteBinaryValue

Description

Writes the value of a binary field to the specified path. If the file exists it will be overwritten.

Syntax

WriteBinaryValue( filepath , fieldId )

Arguments

  • filepath
    • The path to write the field's contents.
  • fieldId
    • The binary field's name. If the field is not a Binary field type an error will be raised.

Example

' Writes a BINARY field's value to a file -- use it to
' land an attachment that arrived inside the dataset. If
' the field is not set, nothing is written and no error
' is raised.
WriteBinaryValue("C:\IMan\Outbound\" & %OrderNo & ".pdf", "DocumentImage")

' Through a FileSystem setup, named first -- here a
' OneDrive for Business drive.
WriteBinaryValue("OneDrive-Finance", "Invoices/" & %OrderNo & ".pdf", "DocumentImage")

WriteTextFile

Description

Writes to a text file. If the file exists it will be overwritten.

Syntax

WriteTextFile( filepath , data )

Arguments

  • filepath
    • The full path of the file.
  • data
    • The data to write to the file.

Example

' Writes text, overwriting the file if it exists. No
' byte-order mark is written, which matters to ERP
' importers that treat one as data.
WriteTextFile("C:\IMan\Outbound\" & %OrderNo & ".txt", %OrderNo & "," & %CustomerCode)