# ListFiles

## `ListFiles` (FB)

FUNCTION\_BLOCK ListFiles EXTENDS CBML.ETrig

### ListFiles

The `ListFiles` The function block enables listing files in a directory. This function block offers configuration options for the directory, sorting criteria and a filter for file names.

### Representation

<figure><img src="/files/703c588663e5f19b0d5a6ed14116e1c67b09b214" alt=""><figcaption></figcaption></figure>

## Usage

The block is used to read files in a specified directory, filter them and return information about the found files and directories.

## Inputs

* **sDirectoryName:** STRING(254) The path of the directory to be searched. By default this is './'.
* **eSortBy:** SORT\_BY The criterion by which the files should be sorted. By default this is by last modification date.
* **sContains:** STRING A filter that specifies which substring the file names must contain. By default this is '.csv'.
* **itfFileList:** COL.ISortedList2 An interface to a sorted list into which the filtered file entries are inserted.

## Outputs

* **udiFilesInDirectory:** UDINT The total number of files in the directory.
* **udiDirectoriesInDirectory:** UDINT The number of directories in the directory.
* **udiFilteredFilesInDirectory:** UDINT The number of files that match the filter criteria.

## Processing logic

1. The FB opens the directory asynchronously and reads the file information.
2. For each file in the directory it checks whether it meets the filter criteria.
3. Filtered files are inserted into the provided sorted list.
4. The FB returns the number of files, directories and filtered files.

InOut:

| Scope  | Name                          | Type               | Initial                     | Inherited from |
| ------ | ----------------------------- | ------------------ | --------------------------- | -------------- |
| Input  | `xExecute`                    | `BOOL`             |                             | ETrig          |
| Output | `xDone`                       | `BOOL`             |                             | ETrig          |
| Output | `xBusy`                       | `BOOL`             |                             | ETrig          |
| Output | `xError`                      | `BOOL`             |                             | ETrig          |
| Input  | `sDirectoryName`              | `STRING(254)`      | './'                        |                |
| Input  | `eSortBy`                     | SORT\_BY           | SORT\_BY.LAST\_MODIFICATION |                |
| Input  | `sContains`                   | `STRING`           | '.csv'                      |                |
| Input  | `itfFileList`                 | `COL.ISortedList2` |                             |                |
| Output | `udiFilesInDirectory`         | `UDINT`            |                             |                |
| Output | `udiDirectoriesInDirectory`   | `UDINT`            |                             |                |
| Output | `udiFilteredFilesInDirectory` | `UDINT`            |                             |                |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.powerio.com/hub/codesys-hvac/en/hvac-library/functionblocks/fileviewer/listfiles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
