Dinu Mihai
Dinu Mihai

Reputation: 3

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?

Upvotes: 0

Views: 51

Answers (2)

htrcode
htrcode

Reputation: 26

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

Upvotes: 1

Trimonu
Trimonu

Reputation: 44

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)

Upvotes: 0

Related Questions