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,712
  • 4
  • 21
  • 33

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
  • 5,083
  • 8
  • 39
  • 72
0

If you already have a pointer to the file:

if f.closed:
    print('file is closed')
Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331