I would like to find via Python script if an application has opened a file. I know there is a lot of proposition out there, but none seems to be doing excactly what I want. I have tried a lot of solutions. But still can't get behavior expected. Want I want is to raise an exception when a python script tries to open a file that is open by pdf reader. For example, if I opened a file with a pdf reader, and try to open/rename it via a Python script, it should raise an exception. I have tried multiple pieces of code:
try:
myfile = open("myfile.csv", "r+") # or "a+", whatever you need
except IOError:
print "Could not open file! Please close Excel!"
with myfile:
do_stuff()
In this question, I tested many scripts and none worked perfectly. When I rename pdf file, even when it is open the rename is accepter and at the end.
This makes me wonder is this is impossible or I am doing wrong.