0

Using win32api, how can I determine if a file is opened?

There is an example program WhoUses.exe, but its written in C++.

mingxiao
  • 1,542
  • 4
  • 18
  • 31

2 Answers2

1

Here's an OS agnostic version:

try:
  file = open("thefile.txt", "r+")
except IOError:
  print "File is open!"

Edited to add that your question is a duplicate of check if a file is open in Python

Community
  • 1
  • 1
It'sPete
  • 4,873
  • 5
  • 34
  • 69
0

If you already have a pointer to the file:

if f.closed:
    print('file is closed')
Russia Must Remove Putin
  • 337,988
  • 84
  • 391
  • 326