FB_RemoveDir 1:

This function block can be used to delete a directory from the data storage device. A directory containing files cannot be deleted.


    sNetId    : T_AmsNetId;
    sPathName : T_MaxString;
    ePath     : E_OpenPath := PATH_GENERIC; (* Default: generic file path*)
    bExecute  : BOOL;
    tTimeout  : TIME := DEFAULT_ADS_TIMEOUT;

sNetId: String containing the AMS network identifier of the target device to which the ADS command is directed (type: T_AmsNetId).

sPathName: Name of the directory to be deleted. When the function block is called, only one directory can be deleted. The last component of sPathName must contain the directory name to be deleted (type: T_MaxString).

ePath: This input can be used to select a TwinCAT system path for the directory to be deleted from the target device (type: E_OpenPath).

bExecute: The function block is activated by a rising edge at this input.

tTimeout: States the length of the timeout that may not be exceeded by execution of the ADS command.


    bBusy  : BOOL;
    bError : BOOL;
    nErrId : UDINT;

bBusy: When the function block is activated, this output is set to TRUE and remains set until feedback is received. As long as bBusy is TRUE, no new command can be created.

bError: If an error occurs during command execution, this output is set, once the bBusy output has been reset.

nErrId: Returns the ADS error code or the command-specific error code when the bError output is set.

Command-specific error code

Possible cause


Folder not found or invalid sPathName or ePath parameter.

Example in ST:

See description of FB_CreateDir.


Development environment

Target system type

PLC libraries to include (Category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_System (System)