F_SplitPathName

F_SplitPathName 1:

This function splits a complete path name into its four components. These are stored in the strings named sDrive, sDir, sFileName and sExt.

FUNCTION F_SplitPathName : BOOL

F_SplitPathName 2: Inputs

VAR_INPUT
    sPathName : T_MaxString;
END_VAR

Name

Type

Description

sPathName

T_MaxString

Complete file name as string (type: T_MaxString) in the form: 'X:\DIR\SUBDIR\FILENAME.EXT'.

F_SplitPathName 3: Inputs/outputs

VAR_IN_OUT
    sDrive    : STRING(3);
    sDir      : T_MaxString;
    sFileName : T_MaxString;
    sExt      : T_MaxString;
END_VAR

Name

Type

Description

sDrive

STRING

Drive ID (type: T_MaxString) with a colon ('C:', 'A:' etc.)

sDir

T_MaxString

Directory name (type: T_MaxString) including the leading and trailing backslash ('\BC \INCLUDE\', '\SOURCE\' etc.)

sFileName

T_MaxString

File name (type: T_MaxString)

sExt

T_MaxString

Contains the dot and the file extension (type: T_MaxString) (example: '.C', '.EXE' etc.).

Return parameter

Description

TRUE

No error

FALSE

Error. Check the function parameters.

Sample of a call in ST:

The pathname: C:\TwinCAT\Plc\Project01\Data.txt is split into the following individual components:

sDrive: = 'C:'
sDir: '\TwinCAT\Plc\Project01\'
sFileName: 'Data'
sExt: '.txt'

PROGRAM MAIN
VAR
    bSplit     : BOOL;
    sPathName  : T_MaxString := 'C:\TwinCAT\Plc\Project01\Data.txt';
    sDrive     : STRING(3);
    sDir       : T_MaxString;
    sFileName  : T_MaxString;
    sExt       : T_MaxString;
    bSuccess   : BOOL;
END_VAR

IF bSplit THEN
    bSplit := FALSE;
    bSuccess := F_SplitPathName( sPathName := sPathName,
                sDrive := sDrive,
                sDir := sDir,
                sFileName := sFileName,
                sExt := sExt );
END_IF

Requirements

Development environment

Target system type

PLC libraries to include (Category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_System (System)