IO / File aFunctions

DIR_CREATE

DIR_CREATE(String directoryPath)

Creates the directory and its subsequent sub-directories with the path specified in the argument.

Arguments:
  • directoryPath (java.lang.String) – The directory path which is to be created.
Return-type :

java.lang.String

Returns:

The directory path that was created.

Example:

=DIR_CREATE("C:/AdapChain/test_dir/test_io")

In the above example, the directory test_dir is created with its sub-directory test_io under the directory C:\AdapChain\.

DIR_DELETE

DIR_DELETE(String directoryPath)

Deletes the directory (including its sub-directories) specified by the path in the argument.

Arguments:
  • directoryPath (java.lang.String) – The directory path which is to be deleted.
Return-type :

java.lang.Boolean

Returns:

Returns boolean false if the directory does not exist else true if the directory gets deleted successfully.

Example:

=DIR_DELETE("C:/AdapChain/test_dir/test")

The above example deletes the directory test including its sub-directories.

DIR_GENERATE

DIR_GENERATE(String parentDirectoryPath[, String prefix="temp", String suffix=""])

Generates a new directory under a parent directory and returns the new directory name.

Arguments:
  • parentDirectoryPath (java.lang.String) – The parent directory path under which the new directory needs to be created.
  • prefix (java.lang.String) – (Optional) Prefix, with that the new directory name starts, default prefix is temp.
  • suffix (java.lang.String) – (Optional) Suffix, with that the new directory name ends, default suffix is blank.
Return-type :

java.lang.String

Returns:

The new directory path which is generated.

Example:

=DIR_GENERATE("C:/AdapChain/test_dir", "ad", "p")
=DIR_GENERATE("C:/AdapChain/test_dir", "ad", "p")

The above RBA assignments generates directories with the following names:

  • C:/AdapChain/test_dir/ad0000001p
  • C:/AdapChain/test_dir/ad0000002p

DIR_LIST

DIR_LIST(String baseDirectory[, String wildcard="*", Boolean searchSubDirectories=false, String mode="FILE"])

Gets a list of file or directory objects under a directory.

Arguments:
  • baseDirectory (java.lang.String) – A directory under which the file and directory objects have to be retrieved.
  • wildcard (java.lang.String) – (Optional) The wildcard characters which are used to filter the list of file or directory objects. Default value for this parameter is * (All).
  • searchSubDirectories (java.lang.Boolean) – (Optional) Flag which tells whether to include sub-directories while listing the file or directory objects under a given directory. Default value for this parameter is false.
  • mode (java.lang.String) – (Optional) This parameter controls whether the list contains File, Directory or both objects. Valid values are - FILE, DIR or FILEDIR. Default value for this parameter is FILE.
Return-type :

ITERATOR<String>

Returns:

An iterator pointing to list of files, directories or both.

Example:

Following is the way to get a list of all the files under the directory C:/AdapChain/test_dir_source while creating a RBA family:

LoopAt Iterator : =DIR_LIST("C:/AdapChain/test_dir_source", "*", true)
=> Into Object  : T_DIR_LIST

The files can be retrieved from the variable T_DIR_LIST while looping over the family.

DIR_RENAME

DIR_RENAME(String oldDirectoryPath, String newDirectoryPath)

Changes a directory name to a new name. Returns the new directory path.

Arguments:
  • oldDirectoryPath (java.lang.String) – The old directory path.
  • newDirectoryPath (java.lang.String) – The directory path with the new name.
Return-type :

java.lang.String

Returns:

The new directory path after renaming.

Example:

Following example shows how to rename a directory test_dir to test_dir1:

=DIR_RENAME("C:/AdapChain/test_dir", "C:/AdapChain/test_dir1")

FILE_COPY_TO_DIR

FILE_COPY_TO_DIR(String sourceFilePath, String destinationDirectoryPath[, Boolean deleteSourceIfSuccess=false])

Copies a file from one location to a different directory.

Arguments:
  • sourceFilePath (java.lang.String) – The source file path which is to be copied to destination directory.
  • destinationDirectoryPath (java.lang.String) – The destination directory where the source file is to be copied.
  • deleteSourceIfSuccess (java.lang.Boolean) – (Optional) A flag which indicates whether to delete the source file after copying, default value is “false”.
Return-type :

java.lang.String

Returns:

Destination directory path.

Example:

=FILE_COPY_TO_DIR("C:/AdapChain/test_dir_source/test.txt", "C:/AdapChain/test_dir_target", true)

The RBA assignments in the above example shows the copying of file test.txt to the directory C:/AdapChain/test_dir_target and removes the source file after copying it.

FILE_COPY_TO_FILE

FILE_COPY_TO_FILE(String sourceFilePath, String destinationFilePath[, Boolean deleteSourceIfSuccess=false])

Copies a file from one location to a different path with a same or different name.

Arguments:
  • sourceFilePath (java.lang.String) – The source file path which is to be copied to destination.
  • destinationFilePath (java.lang.String) – The destination file path.
  • deleteSourceIfSuccess (java.lang.Boolean) – (Optional) A flag which indicates whether to delete the source file after copying, default value is false.
Return-type :

java.lang.String

Returns:

Destination file path after copying.

Example:

=FILE_COPY_TO_FILE("C:/AdapChain/test_dir_source/test.txt", "C:/AdapChain/test_dir_target/test_target.txt", true)

The RBA assignments in the above example shows the copying of file test.txt to the directory C:/AdapChain/test_dir_target as test_target.txt and removes the source file after copying it.

FILE_DELETE

FILE_DELETE(String filePath)

Deletes a file specified by the path in the argument. Returns boolean false if the file does not exist else true if the file gets deleted successfully.

Arguments:
  • filePath (java.lang.String) – The filepath which is to be deleted.
Return-type :

java.lang.Boolean

Returns:

Boolean false if the file does not exist else true if the file gets deleted successfully.

Example:

=FILE_DELETE("C:/AdapChain/test_dir/test/test.txt")

The above example deletes the file test.txt.

FILE_GENERATE

FILE_GENERATE(String parentDirectoryPath[, String preNamePart="file", String postNamePart=".tmp"])

Generates a new file under a directory and returns the new file path. Returns the new file path.

Arguments:
  • parentDirectoryPath (java.lang.String) – The parent directory under which the new file is to be generated.
  • preNamePart (java.lang.String) – (Optional) The characters the file name starts with, the default preNamePart is “file”.
  • postNamePart (java.lang.String) – (Optional) The extension of the file, the default postNamePart is “.tmp”.
Return-type :

java.lang.String

Returns:

The new file path.

Example:

=FILE_GENERATE("C:/AdapChain/test_dir_source", "test", "b.tsv")
=FILE_GENERATE("C:/AdapChain/test_dir_source", "test", "b.tsv")

The above RBA assignments create the following files in the directory C:/AdapChain/test_dir_source:

  • C:/AdapChain/test_dir_source/test0000001b.tsv
  • C:/AdapChain/test_dir_source/test0000002b.tsv

FILE_READ_LINES

FILE_READ_LINES(String filePath[, String encoding=platformEncoding])

Reads a file line wise and retrieves it as string.

Arguments:
  • filePath (java.lang.String) – Path of the file which is to be read.
  • encoding (java.lang.String) – (Optional) Encoding of the file.
Return-type :

ITERATOR<String>

Returns:

An iterator that can be used to loop over the lines in the input file.

Example:

Following is the way to get an iterator over the lines in file source_file.txt while creating a RBA family.

LoopAt Iterator : =FILE_READ_LINES("C:/AdapChain/test_dir_source/source_file.txt")
=> Into Object  : T_LINE_FILE

The lines can be retrieved from the variable T_LINE_FILE anytime while looping over the family.

FILE_RENAME

FILE_RENAME(String oldFilePath, String newFilePath)

Changes a file name to a new name. Returns the new file path.

Arguments:
  • oldFilePath (java.lang.String) – The old file path.
  • newFilePath (java.lang.String) – The file path with the new name.
Return-type :

java.lang.String

Returns:

The new file path after renaming.

Example:

Following example shows how to rename a file testA.txt to testB.txt:

=FILE_RENAME("C:/AdapChain/test_dir/testA.txt", "C:/AdapChain/test_dir/testB.txt")

FILE_TO_STRING

FILE_TO_STRING(String filePath[, String encoding=platformEncoding])

Gives the string representation of a file.

Arguments:
  • filePath (java.lang.String) – The file path which is to be converted to string.
  • encoding (java.lang.String) – (Optional) The file encoding format, default is platform Encoding.
Return-type :

java.lang.String

Returns:

The string representation of a file.

Example:

T_STRING = FILE_TO_STRING("C:/AdapChain/test_dir_source/test.txt")

The above assignment assigns the string representation of file test.txt to the variable T_STRING.

PATH_NORMALIZE

PATH_NORMALIZE(String path)

Returns the normalized value of the input path i.e.:

  • Converts all back slashes ‘\’ to forward slashes ‘/’.
  • Resolves relative paths with .. and . chars.
Arguments:
  • path (java.lang.String) – The input path value that needs to be normalized.
Return-type :

java.lang.String

Returns:

Returns the normalized path value.

Example:

=PATH_NORMALIZE("C:\AdapChain\AdapLink service\..")
Output: "C:/AdapChain"

PATH

PATH(String parent, String child[, boolean normalize=false])

Resolves the final path for a given parent path and relative child path.

Arguments:
  • parent (java.lang.String) – The parent path.
  • child (java.lang.String) – The child path relative to parent.
  • normalize (java.lang.Boolean) – (Optional) when true then the value returned is normalized.
Return-type :

java.lang.String

Returns:

Returns the normalized path value.

Example:

=PATH("C:\AdapChain", "backup")
Output: "C:\AdapChain\backup" - The directory separator is automatically added
=PATH("C:\AdapChain\", "backup")
Output: "C:\AdapChain\backup" - The directory separator is not added twice
=PATH("C:\AdapChain\AdapLink service\..", "backup", true)
Output: "C:/AdapChain/backup"

URL_DOWNLOAD_TO_DIR

URL_DOWNLOAD_TO_DIR(String URL, String targetDir[, String defaultFileName=""])

Downloads an URL to local file system in a directory. Returns the file path after downloading the URL.

Arguments:
  • URL (java.lang.String) – An URL to download.
  • targetDir (java.lang.String) – The target directory where the URL is to be downloaded.
  • defaultFileName (java.lang.String) – (Optional) A file name which is used to save the file after downloading the URL, in case the URL does not contain the file name in it. The default file name is “”.
Return-type :

java.lang.String

Returns:

The file path after downloading the URL.

Example:

=URL_DOWNLOAD_TO_DIR("http://www.adapchain.com", "C:/AdapChain/test_dir_target", "index.html")

The above RBA assignment downloads the html index file from the URL “http://www.adapchain.com” and saves it as index.html under the directory C:/AdapChain/test_dir_target in local system.

URL_DOWNLOAD_TO_FILE

URL_DOWNLOAD_TO_FILE(String URL, String targetFile)

Downloads an URL to local file system as a file. Returns the file path after downloading the URL.

Arguments:
  • URL (java.lang.String) – An URL to download.
  • targetFile (java.lang.String) – The target file the URL is to be downloaded as.
Return-type :

java.lang.String

Returns:

The file path after downloading the URL.

Example:

=URL_DOWNLOAD_TO_FILE("http://www.adapchain.com", "C:/AdapChain/test_dir_target/index.html")

The above RBA assignment downloads the html index file from the URL “http://www.adapchain.com” and saves it as C:/AdapChain/test_dir_target/index.html in local system.