Subject Re: Watching a folder
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Sun, 15 Jul 2018 19:13:52 +0530
Newsgroups dbase.getting-started

On 15/07/2018 14:38, Michael wrote:
> Hi Guys,
>
> I need to check a folder to see if a .txt file has been written in the folder and is closed by another writing party.
>
> I created a do while loop using file() to see if the file exists or not and then sleep a second to make sure the file has been written and closed as there is no file locking.
>
> My concern is that if something goes wrong in writing the file by the  third party it could hang me in an endless loop.
>
> Is there a better way to check a folder if a file has been written yet or not? and wait for it to be written without using a loop, for eg: using timer? to check every second or so?
>
> Any thoughts/suggestions?
>
> Michael.
>

Hello Michael,

I am not aware of how you are checking for the existence of locks. I am
just concentrating on the prevention of endless loop.

lock_exists = true
mtime = seconds()
do while lock_exists and (seconds() - mtime) <15
        if not lock_exists()
                lock_exists = false
        endif
enddo

In the above lock_exists() is your function for checking of existence of
file / locks.
You can easily select the duration you want this loop to execute.

A flaw in this loop it will exit immediately if the code is run at 12 am
As seconds() returns the number of seconds since midnight.

But there are alternatives to that also if your program will run 24 hours.

This is an untested code for demo purposes only hence cannot assure
error free running. It may need to be fine tuned.

Regards
Akshat


Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0