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

VAR_INPUT
    sPathName : T_MaxString;
END_VAR

sPathName: Complete file name as string: 'X:\DIR\SUBDIR\FILENAME.EXT'.

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

sDrive: Drive name with a double point ('C:', 'A:' etc.).

sDir: Directory name inlusive the leading and ending backslash ('\BC \INCLUDE\', '\SOURCE\' etc.).

sFileName: File name.

sExt: Contains the point that starts the name extension ('.C', '.EXE' etc.).

Return parameter

Description

TRUE

No error

FALSE

Error. Check the function parameter.

 

Example for a call in ST:

The path name: 'C:\TwinCAT\Plc\Project01\Data.txt' is splitted in the following 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

PLC Libraries to include

TwinCAT v2.10.0 Build > 1307

PC or CX (x86)
CX (ARM)

TcSystem.Lib