fsDirCatalog (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


fsDirCatalog is used to return the contents of the current directory - including sub-directories and files.

When a sub-directory or file is created it is registered in the file system. The file system does not sort the contents by type (file or directory) or alphabetically but it assigns an index number to the file or directory as it is created. This index number is the input of the fsDirCatalog function, and it will return the name of the file or directory the index refers to.

 

The index number of a file or sub-directory may change when the content of a directory is modified, for example when files or sub-directories are created, deleted or moved.

 

Note: The working directory is on a per thread basis.

 

 

Input:

index : INT (1..n)

Index entry to return. The first entry is 1.

 

Returns: STRING

Name of file or directory at the index specified. Empty if none.

 

Declaration:

FUNCTION fsDirCatalog : STRING;
VAR_INPUT
  index : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
FUNCTION directory_dump;
VAR
  i   : INT;
  str : STRING;
END_VAR;
  // Print current directory
  DebugMsg(message := "Directory: " + fsDirCurrent());
  // Iterate directory
  REPEAT
     str := fsDirCatalog(index := i);
    IF strLen(str := str) > 0 THEN
        DebugMsg(message := str);
    END_IF;
     i := i + 1;
  UNTIL strLen(str := str) = 0
  END_REPEAT;
  // If directory is empty, print it
  IF i = 1 THEN
    DebugMsg(message := "<EMPTY>");
  END_IF;
END_FUNCTION;