pdk.flow.File

functions to work with files

All functions


readCSV

It is used to parse and extract data stored in CSV format.

The system parses the CSV file without using headers, which means that the first row of the file will be interpreted and parsed into the result records array as the first element.

The parsing algorithm uses values order to map values into structure.

It's better to delete the line containing headers from the CSV file

Arguments:

Result:

  • No variable is returned. Records array contains all values from the input file.

Possible exceptions

Example:

CSV:

Personal Number,First Name,Last Name,Date of birth,Type
personalNo0001,firstName1,lastName1,1991-01-01,vip
personalNo0002,firstName2,lastName2,1986-04-12,normal
personalNo0003,firstName3,lastName3,1973-10-28,normal
personalNo0004,firstName4,lastName4,1998-06-04,vip
personalNo0005,firstName5,lastName5,1989-03-20,normal

Structure Client:

Order of attributes is important

Result:

records :: pdk.code.Array<Client> = [
{ 
    "personalNumber": "Personal Number",
    "firstName": "First Name",
    "lastName": "Last Name",
    "dob": "Date of birth",
    "clientType": "Type"
},
{ 
    "personalNumber": "personalNo0001",
    "firstName": "firstName1",
    "lastName": "lastName1",
    "dob": "1991-01-01",
    "clientType": "vip"
},
...
]

writeCSV

It is used for generating a new CSV file and writing data from an input array that contains properties of simple types only.

Each record from the input array will be written on its own line. Each record property will be transformed into pdk.core.String before being written.

Avoid using structures containing properties with non-simple types. This may result in unexpected outcomes.

Avoid this:

Use simple properties:

Arguments:

Result:

Possible exceptions

Example:

records :: pdk.code.Array<Client> = [
    { 
        "personalNumber": "personalNo0001",
        "firstName": "firstName1",
        "lastName": "lastName1",
        "dob": "1991-01-01",
        "clientType": "vip"
    },
    { 
        "personalNumber": "personalNo0002",
        "firstName": "firstName2",
        "lastName": "lastName2",
        "dob": "1986-04-12",
        "clientType": "normal"
    }
]

File content:

personalNo0001,firstName1,lastName1,1991-01-01,vip
personalNo0002,firstName2,lastName2,1986-04-12,normal

rename

renames file

Arguments:

Result:

  • No variable is returned. The input file was renamed.

Possible exceptions


toByteArray

Returns a byte array as a sequence of bytes that represents the contents of the File.

Arguments:

Result:

Possible exceptions


fromByteArray

Creates a new temporary file with the file name provided as an argument and the specified byte content.

Arguments:

Result:

Possible exceptions

Last updated