# Log file directory listing and monitoring

**URL:** <https://forum.inductiveautomation.com/t/log-file-directory-listing-and-monitoring/48269>\
**Category:** Ignition\
**Created:** [June 28, 2021, 12:20pm UTC](https://forum.inductiveautomation.com/t/log-file-directory-listing-and-monitoring/48269 "2021-06-28T12:20:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yves.morrissette](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yves.morrissette/32/21307_2.png) [@yves.morrissette](https://forum.inductiveautomation.com/u/yves.morrissette)\
**Post date:** [June 28, 2021, 12:20pm UTC](https://forum.inductiveautomation.com/t/log-file-directory-listing-and-monitoring/48269/1 "2021-06-28T12:20:14Z")

</div>

Hi,

I’m looking to monitor a specific directory that contains log files. I want to check the number of files that are present, as well as their dates and sizes.

Is there a function for that? I was hoping to find something in system.file but found nothing that could do what I want.

Thanks!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 28, 2021, 12:27pm UTC](https://forum.inductiveautomation.com/t/log-file-directory-listing-and-monitoring/48269/2 "2021-06-28T12:27:09Z")

</div>

There is no built in function for monitoring a directory. I would recommend a Gateway timer script that iterates through the desired directory and saves the results to the database so that the next iteration, it can compare and see what if any changes happened. I would probably use the `os` jython library.

```auto
import os
b = os.path.getsize("/path/isa_005.mp3")

```

b would give you the size in bytes. So you’ll probably want to write a function to convert from bytes to kilobytes or megabytes or however you want to view it.

You can also use `os` to iterate through a directory with `os.walk` and modify the logic

```auto
for (root,dirs,files) in os.walk('someDirectory', topdown=true):
    print root
    print dirs
    print files

```

You’ll have to craft the logic yourself but I think these two functions should get you pretty much there (along with any help functions you find yourself needing).

Last note - if you know when you expect file changes, ie when some button is pushed or some other part of your Ignition application is run, you might prefer a gateway message handler to check at that moment, and perhaps to keep a gateway timer script with a long interim that runs in case of any misses.

Edit: To get date modified of the files - use `os.path.getmtime(filepath)`

---

<div class="post-metadata">

**Author:** ![yves.morrissette](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yves.morrissette/32/21307_2.png) [@yves.morrissette](https://forum.inductiveautomation.com/u/yves.morrissette)\
**Post date:** [June 28, 2021, 10:03pm UTC](https://forum.inductiveautomation.com/t/log-file-directory-listing-and-monitoring/48269/3 "2021-06-28T22:03:14Z")

</div>

Thanks, this works great!
