How to check if files are still created?


I would like to make a script to check whether or not files are still being created inside a folder. We can consider for our problem that there are no more files being created if let’s say for 5 sec the list of files present in that folder remains unchanged. Can anyone help me with this issue?

Asked By: Dinu Mihai



By created I’m assuming you mean existing, anyway to do that:

import os
entries = os.listdir('my_directory/')

then check length of entries with len(entries)

Answered By: Trimonu

You can use inotifywait to watch for events on a file or a directory.

inotifywait -m -e create /path/to/your/dir

It will show you the events and exits if no more event happens after 5 seconds.

inotifywait --timeout 5 -qm -e create /path/to/your/dir

By default it will use 5 seconds but you can change it by putting --timeout a

Answered By: htrcode
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.