> For the complete documentation index, see [llms.txt](https://support.powerio.com/hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.powerio.com/hub/codesys-hvac/en/hvac-library/functionblocks/fileviewer/listfiles.md).

# 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="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2FF1lynplpVWo49L95Qpwf%2FListFiles.png?alt=media&amp;token=ae326f0f-7814-45e1-a585-793e9d54d854" alt=""><figcaption></figcaption></figure>

## Usage

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

## 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 are to be sorted. By default, this is by the last modification date.
* **sContains:** STRING A filter that specifies which string 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 meet 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 is checked whether it meets the filter criteria.
3. Filtered files are inserted into the passed 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
