---
title: "How to monitor the latest version of all files whose name changes dynamically in a dated directory"
description: "Monitoring the latest version of dynamically named files in a dated directory requires using the Dynamic Files option in FKM. The setup involves configuring the path, regex, and date functions to capture the newest files automatically."
url: "https://docs.itrsgroup.com/docs/faq/geneos/360010847174-geneos-how-to-monitor-the-latest-version-of-all-files-whose-name-changes-dynamically-in-a-dated-directory/index.html"
---

**Note**



Use the Dynamic Files option to accomplish this within FKM.




To demonstrate, we have a dated directory and we want to monitor the latest version of every filename. Notice the screenshot below shows the latest version of each file is `Prod\_ProcessA-13.log`, `Prod\_ProcessB-13.log`, and `Prod\_ProcessC-13.log`.

![Sample log files in a directory](https://docscdn.itrsgroup.com/faq/images/geneos/sample-filenames-directory.png)

The FKM setup would be as follows:

1. Select the **dynamicFiles** drop-down option under Source.

2. Click the **Dynamic Files** button which opens the Dynamic files window as seen below:

![Dynamic Files in FKM sampler](https://docscdn.itrsgroup.com/faq/images/geneos/dynamic-files-FKM.png)

3. In the Path field, put the complete file path and use the today function followed by `\*.log`. This allows the FKM sampler to automatically monitor files in the folder with today’s date in its name.

4. In the Regex field, put the following Regex expression:

```
^.*Logs\/\d+-\d+-\d+\/(.*)-\d+.log$
```

5. For the FKM sampler to grab the latest version of each file in the directory, the regex expression needs to be unique. We do that by including the `Logs\/` sub-folder in the regex expression since the Logs sub-folder will remain the same.

This is followed by the pattern for the date folder:

```
\d+\d+\d+\/
```

We have a capture group `(.\*)` in the expression that will hold a portion of the filename up until the dash (-) number portion dot (.) log. The capture group is used in the name column of the dataview.

The following `-\d+` ensures we consider the last dash in the filename followed by the number. The `.log` at the end will apply only to files with that file extension.

Below is the Metrics view of the FKM sampler displaying `Prod\_ProcessA-13.log`, `Prod\_ProcessB-13.log`, and `Prod\_ProcessC-13.log` files.

![FKM metrics view](https://docscdn.itrsgroup.com/faq/images/geneos/FKM-metrics-view.png)

For more information, see [FKM - Dynamic Files](https://docs.itrsgroup.com/docs/geneos/current/collection/fkm-config/#files--file--source) and [date generation function](https://docs.itrsgroup.com/docs/geneos/current/collection/fkm/#use-date-generation-function-when-using-dynamic-files-option).

Below is the FKM - dynamic example sampler:

```
<sampler name="FKM - dynamic example">
    <plugin>
        <fkm>
            <isPCREMode>
                <data>true</data>
            </isPCREMode>
            <files>
                <file>
                    <source>
                    <dynamicFiles>
                        <path>
                            <data>/export/home/mmuniz/fkm_dynamic_example/Logs/<today %Y-%m-%d>/*.log</data>
                        </path>
                        <pattern>
                            <data>
                                <regex>^.*Logs\/\d+-\d+-\d+\/(.*)-\d+.log$</regex>
                            </data>
                        </pattern>
                    </dynamicFiles>
                    </source>
                    <alias>
                        <data>%1</data>
                    </alias>
                </file>
            </files>
        </fkm>
    </plugin>
</sampler>
```


**Note**



This sampler was set up on version GA5.9.0.





