How to check if a file is open before overwriting it

Hi All,
I have a function that overwrites a csv file.
Is there a way for uxp to check if the csv file is currently open?
If its open, the user should then get a warning message to close it first.

I was thinking of trying to delete the file, and if it cannot be deleted because its open then an alert message would pop up, but I also dont know the function of deleting a file as well.

If anyone can help or have an idea how this is done, it would really be greatly appreciated. Thank you!