Checking if a file is already in use

BlitzMax Forums/BlitzMax Programming/Checking if a file is already in use

danibert(Posted 2010) [#1]
Hello,

I´m reading files into my BMax app to create some checksums. To ensure the checksums to be calculated properly, I´d like to check if the file is already opened by another process or application.
Important: It needs to work on Windows, Linux and Mac.

My current approach is to open the files with OpenStream(path:String, True, True). This locks the file for opening with other applications. But if the file is already opened, I get no error message.

How ca I realize this?
Thank you in advance for all tipps ald hints


TaskMaster(Posted 2010) [#2]
Try to open the file for writing.

If a program has the file opened for writing, then you should not be able to open it for writing.

If it is open for reading already, then you know it is not going to be modified so you do not have to worry about it.