Home > Back-end >  How to check if files are still created?
How to check if files are still created?

Time:11-25

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?

Thank you

CodePudding user response:

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 after the command.

Please upvote if it helps!

CodePudding user response:

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)

  • Related