SAP Help Home SAP Intelligent RPA Help Portal SAP Intelligent RPA Community

Module - File System (FS)

Collection of functions for accessing and manipulating File System objects such as Copy, Move...

Author:
  • SAP Intelligent RPA R&D team

Activities

Move (File/Folder)

Move a file (or a folder) from one location to another.


Technical Name Type Minimal Agent Version
move asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
source string mandatory Source path.
destination string mandatory Destination path.

Sample Code:

await irpa_core.fs.move('./FSO/folder1', './FSO/folder2');

Sample Code:

await irpa_core.fs.move('./FSO/folder1/text1.txt', './FSO/folder2/text2.txt');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file exists on your machine.


Copy (File/Folder)

Copy a file (or folder) from one location to another.


Technical Name Type Minimal Agent Version
copy synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
source string mandatory Source path.
destination string mandatory Destination path.
overwrite boolean optional Overwrite option.

Sample Code:

await irpa_core.fs.copy('./FSO/folder1', './FSO/folder2', true);

Sample Code:

await irpa_core.fs.copy('./FSO/folder1/text1.txt', './FSO/folder2/text2.txt',true);

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Get Information

Retrieve information about a specified file or folder, such as its size for instance.


Technical Name Type Minimal Agent Version
get asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
path string mandatory File or directory path.

Output Parameters:

Name Type Description
obj irpa_core.fsStats Object.

Sample Code:

const stats = await irpa_core.fs.get('./FSO/folder1');

Sample Code:

const stats = await irpa_core.fs.get('./FSO/folder1/text1.txt');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Remove (File/Folder)

Remove a file or a folder from a specified location.


Technical Name Type Minimal Agent Version
remove asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
path string mandatory Path of the file (or folder) to remove.

Sample Code:

await irpa_core.fs.remove('./FSO/folder');

Sample Code:

await irpa_core.fs.remove('./FSO/folder/text.txt');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Exist (File/Folder)

Check whether a file or a folder exists in a specified location.


Technical Name Type Minimal Agent Version
exist asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
path string mandatory Path of the location.

Output Parameters:

Name Type Description
exist boolean Returns true if the file (or folder) exists, false otherwise.

Sample Code:

const exist = await irpa_core.fs.exist('./FSO/folder');

Sample Code:

const exist = await irpa_core.fs.exist('./FSO/folder/text.txt');



Rename (File/Folder) New

Allow to rename an existing file or folder.


Technical Name Type Minimal Agent Version
rename asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
sourcePath New string mandatory The source path of the file or folder to rename.
oldName New string mandatory The current name of the folder or file.
newName New string mandatory The new name of the folder or file.

Sample Code:

await irpa_core.fs.rename('./FSO/folder', 'folder1', 'folder2');

Sample Code:

await irpa_core.fs.rename('./FSO/folder/', 'text.txt', text2.txt);



Is URL

Check whether a path is a valid URL.


Technical Name Type Minimal Agent Version
isWebURL synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
path string mandatory Path of the URL to check.

Output Parameters:

Name Type Description
Returns boolean Returns true if the specified path is a valid URL, false otherwise.

Sample Code:

const res = irpa_core.isWebURL('\\\\myServer\\myFolder\\myFile.pdf'); // false

Sample Code:

const res = irpa_core.isWebURL('http://myServer/myFolder/myFile.pdf'); // true



Is Absolute Path

Check whether a path is absolute or relative. This activity returns "true" if the tested path is an absolute path. An absolute path points to the same location in a file system, regardless of the current working directory. To do that, it must include the root directory. By contrast, a relative path starts from some given working directory.


Technical Name Type Minimal Agent Version
isPathAbsolute synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
path string mandatory Path to check.

Output Parameters:

Name Type Description
Returns boolean Returns true if the specified path is an absolute path, false otherwise.

Sample Code:

if (irpa_core.isPathAbsolute(path)) { }



Create Folder

Create a folder within a specified path.


Technical Name Type Minimal Agent Version
folder.create synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
folderPath string mandatory Folder path.

Sample Code:

irpa_core.fs.folder.create('./FSO/folder');



Get File Collection

Return a collection (list) of files belonging to a specified folder.


Technical Name Type Minimal Agent Version
folder.getFileCollection asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
folderPath string mandatory Folder path.
full boolean optional With full path (false by default).

Output Parameters:

Name Type Description
coll Array. Collection (list) of files.

Sample Code:

const files = await irpa_core.fs.folder.getFileCollection('./FSO/folder');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Get Folder Collection

Return a collection (list) of folders belonging to a specified folder path.


Technical Name Type Minimal Agent Version
folder.getFolderCollection asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
folderPath string mandatory Folder path.
full boolean optional With full path (false by default).

Output Parameters:

Name Type Description
coll Array. Collection (list) of folders.

Sample Code:

const folders = await irpa_core.fs.folder.getFolderCollection('./FSO/folder');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Open Folder Dialog

Open an Explorer dialog to select a folder path. Specific for attended usage (requires user response).


Technical Name Type Minimal Agent Version
folder.openDialogFolder asynchronous WIN-2.0.0 (WIN for Windows)

Output Parameters:

Name Type Description
path string Selected folder.

Sample Code:

await irpa_core.fs.folder.openDialogFolder();

Errors:

Error Class Package Description
Canceled irpa_core dialog canceled


Delete All Files

Delete all the files from a specified folder. Use with caution because all files will be deleted and OS recovery may not work depending on your settings or configuration (network drive).


Technical Name Type Minimal Agent Version
file.deleteInFolder asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
folderPath string mandatory Name of the folder from which all the files will be deleted.

Sample Code:

await irpa_core.fs.file.deleteInFolder('./FSO/folder');



Get Absolute Path Name (File)

Return the absolute path name of a file. An absolute path points to the same location in a file system, regardless of the current working directory. To do that, it must include the root directory.


Technical Name Type Minimal Agent Version
file.getAbsolutePathName synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.

Output Parameters:

Name Type Description
name string Absolute path name of the file.

Sample Code:

irpa_core.fs.file.getAbsolutePathName('c:\temp\file.txt');



Get Base Name (File)

Return the basename of a file. A basename is the name of a file without path and extension.


Technical Name Type Minimal Agent Version
file.getBaseName synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.

Output Parameters:

Name Type Description
baseName string Basename of the file.

Sample Code:

irpa_core.fs.file.getBaseName('c:\temp\file.txt'); // returns 'file'



Get Extension Name (File)

Return the extension name of a specified file.


Technical Name Type Minimal Agent Version
file.getExtensionName synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.

Output Parameters:

Name Type Description
name string Extension name.

Sample Code:

irpa_core.fs.file.getExtensionName( 'c:\temp\file.txt' ); // returns 'txt'



Get File Name

Return the full name of a specified file (basename and extension).


Technical Name Type Minimal Agent Version
file.getFileName synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.

Output Parameters:

Name Type Description
fullName string Full name of the file.

Sample Code:

irpa_core.fs.file.getFileName( 'c:\temp\file.txt' ); // returns 'file.txt'



Get Folder Path

Get the folder path of a provided file.


Technical Name Type Minimal Agent Version
file.getFolderPath synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.

Output Parameters:

Name Type Description
fullName string Full path of the folder.

Sample Code:

irpa_core.fs.file.getFolderPath( 'c:\\temp\\file.txt' ); // returns 'c:\\temp\\'



Create File

Create an empty file in a specified location.


Technical Name Type Minimal Agent Version
file.create asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.

Sample Code:

await irpa_core.file.create( 'c:\temp\file.txt' );



Open File Dialog

Open an Explorer dialog to select a file path. Specific for attended usage (requires user response).


Technical Name Type Minimal Agent Version
file.openDialogFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
rootFolder string optional Root folder.

Output Parameters:

Name Type Description
path string Selected file name.

Sample Code:

await irpa_core.fs.file.openDialogFile('c:\\');

Errors:

Error Class Package Description
Canceled irpa_core dialog canceled


Read File

Read the content (text) of a specified file based on a supplied encoding (by default UTF-8).


Technical Name Type Minimal Agent Version
file.read asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.
encoding irpa_core.enums.file.encoding optional UTF8 File encoding.

Output Parameters:

Name Type Description
content string Content of the file.

Sample Code:

const txt = await irpa_core.fs.file.read('c:\temp\file.txt', irpa_core.enums.file.encoding.ASCII);

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Unzip File

Unzip a ZIP file in a specified folder (without password).


Technical Name Type Minimal Agent Version
file.unzip asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
zipFile string mandatory Name of the ZIP file to be unzipped.
unzipDir string mandatory Name of the folder in which the ZIP file will be extracted.

Sample Code:

await irpa_core.fs.file.unzip("c:\\temp\\result.zip", "c:\\temp\\result");

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Write File

Write text content in a file based on a supplied encoding (UTF-8 by default).


Technical Name Type Minimal Agent Version
file.write asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.
content string mandatory Text to be written.
encoding irpa_core.enums.file.encoding optional File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).
overwrite boolean optional If set to true, overwrites the existing file (true by default).

Sample Code:

await irpa_core.fs.file.write('c:\temp\file.txt', 'my text here', irpa_core.enums.file.encoding.UTF8);

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Append File

Append a text content in a file based on a supplied encoding (UTF-8 by default).


Technical Name Type Minimal Agent Version
file.append asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory Path of the file.
content string mandatory Text to append.
encoding irpa_core.enums.file.encoding optional File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).

Sample Code:

await irpa_core.fs.file.append('c:\temp\file.txt', 'my text here', irpa_core.enums.file.encoding.UTF8);

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Zip (File/Folder)

Archive a set (collection) of files or folders in a ZIP file.


Technical Name Type Minimal Agent Version
file.zip asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
files Array. mandatory Array of files or folders to be zipped.
zipFile string mandatory Generated ZIP file.

Sample Code:

const files = [ 'c:\\temp\\file1.txt', 'c:\\temp\\file2.txt', 'c:\\temp\\file3.txt', 'c:\\temp\\file4.txt' ]; await irpa_core.fs.file.zip( files, 'c:\\temp\\result.zip' );

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Open Lines Reader

Open a file to read lines with pagination.


Technical Name Type Minimal Agent Version
file.openLinesReader synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
path string mandatory The file path.

Sample Code:

await irpa_core.fs.file.openLinesReader( 'c:\\temp\\file.txt' );

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Close Lines Reader

Close a file to read lines with pagination.


Technical Name Type Minimal Agent Version
file.closeLinesReader synchronous WIN-2.0.0 (WIN for Windows)

Sample Code:

await irpa_core.fs.file.closeLinesReader();



Read Lines

Read lines with pagination. Please define properly the amount of information to process.


Technical Name Type Minimal Agent Version
file.readLines asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
pagination number mandatory The number of lines.

Output Parameters:

Name Type Description
Lines Array. Array of files.

Sample Code:

await irpa_core.fs.file.readLines( 100 );



Write CSV File

Write a CSV file.


Technical Name Type Minimal Agent Version
file.writeCSVFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
data Array. mandatory Origin data.
delimiter string optional , Delimiter (comma by default).
hasHeaders boolean optional true Include the headers or not (included by default).
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).
carriageReturn irpa_core.enums.file.carriageReturn optional CR+LF Carriage Return (by default, irpa_core.enums.file.carriageReturn.CRLF').

Sample Code:

const res = await irpa_core.fs.file.writeCSVFile('path', 'delimiter', true, 'encoding');



Read CSV File

Read a CSV file. Please define properly the amount of information to process. The activity tries to convert automatically the data, for instance if in the file you have a data \"true\" or \"100002\", the activity converts automatically to boolean or number. If you cast in the data type you need to declare a boolean or number in the field of the data type.


Technical Name Type Minimal Agent Version
file.readCSVFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
delimiter string optional The delimiter (empty by default for auto-detect).
hasHeaders boolean optional true Include the headers or not (included by default).
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).
carriageReturn irpa_core.enums.file.carriageReturn optional None Carriage Return (by default for auto-detect, irpa_core.enums.file.carriageReturn.None').

Output Parameters:

Name Type Description
data Array. Data populate.

Sample Code:

const res = await irpa_core.fs.file.readCSVFile('path', 'delimiter', true, 'encoding');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Read Lines from CSV File

Open a CSV file and read its lines.


Technical Name Type Minimal Agent Version
file.openCSVLineReader synchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
delimiter string optional The delimiter (empty by default for auto-detect).
hasHeaders boolean optional true Include the headers or not (included by default).
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).
carriageReturn irpa_core.enums.file.carriageReturn optional None Carriage Return (by default for auto-detect, irpa_core.enums.file.carriageReturn.None').

Sample Code:

const res = await irpa_core.fs.file.openCSVLineReader('path', 'delimiter', true, 'encoding');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Read CSV Lines

Read CSV lines using the number of lines. Please define properly the amount of information to process. The activity tries to convert automatically the data, for instance if in the file you have a data \"true\" or \"100002\", the activity converts automatically to boolean or number. If you cast in the data type you need to declare a boolean or number in the field of the data type.


Technical Name Type Minimal Agent Version
file.readCSVLines asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
numberOfLines number mandatory The number of lines.

Output Parameters:

Name Type Description
List Array. Array of files.

Sample Code:

await irpa_core.fs.file.readCSVLines( 100 );



Write JSON File

Write a JSON file.


Technical Name Type Minimal Agent Version
file.writeJSONFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
data Array. mandatory Origin data type.
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).

Sample Code:

const res = await irpa_core.fs.file.writeJSONFile('path', data, 'encoding');



Read JSON File

Read a JSON file.


Technical Name Type Minimal Agent Version
file.readJSONFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).

Output Parameters:

Name Type Description
data Array. Data populate.

Sample Code:

const res = await irpa_core.fs.file.readJSONFile('path', 'encoding');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.


Write XML File

Write an XML file.


Technical Name Type Minimal Agent Version
file.writeXMLFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
data Array. mandatory Origin data types.
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).

Sample Code:

const res = await irpa_core.fs.file.writeXMLFile('path', data, 'encoding');



Read XML File

Read an XML file. The activity tries to convert automatically the data, for instance if in the file you have a data \"true\" or \"100002\", the activity converts automatically to boolean or number. If you cast in the data type you need to declare a boolean or number in the field of the data type.


Technical Name Type Minimal Agent Version
file.readXMLFile asynchronous WIN-2.0.0 (WIN for Windows)

Input Parameters:

Name Type Attributes Default Description
filePath string mandatory File path.
encoding irpa_core.enums.file.encoding optional UTF8 File encoding (by default, “irpa_core.enums.file.encoding.UTF8”).

Output Parameters:

Name Type Description
data Array. Data populate.

Sample Code:

const res = await irpa_core.fs.file.readXMLFile('path', 'encoding');

Errors:

Error Class Package Description
NotFound irpa_core The requested file has not been found, please check that the file is existing on your machine.