Check whether a given file is open or closed

Windows specific forum
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Check whether a given file is open or closed

Post by BorisTheOld »

luis wrote:But what's the practical use for something like this ?

I'm asking because:

Code: Select all

if FileIsClosed ("file.txt") ; ok the file was not in use, some time ago, inside that proc
    ; but now ? 
endif
Agreed! There is no practical use, because as you point out there's nothing to stop another task from opening the file before action is taken on the result of the test.

In a shared environment, every task/user has to be working to the same set of rules. This might be a complex file locking protocol that allows files to be updated, shared, and copied, all without data loss. Or it might be something as simple as kicking everyone off the network while files are copied.

I've found that the later solution works well and is simple to implement. :D
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply