[Python] 纯文本查看 复制代码 from ctypes import windll
import time
import win32file
from win32file import *
def is_open(filename):
try:
#首先获得句柄
vHandle =win32file.CreateFile(filename, GENERIC_READ, 0, None, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, None)
#判断句柄是否等于INVALID_HANDLE_VALUE
print(vHandle)
if int(vHandle)==INVALID_HANDLE_VALUE:
print("# file is already open")
return True # file is already open
win32file.CloseHandle(vHandle)
except Exception as e:
print(e)
vHandle=(CreateFile(filename,
0,
0,
None,
OPEN_EXISTING,
0,
None ))
win32file.CloseHandle(vHandle)
return True
print (is_open('2020年公司经营总表.xlsx'))
这样还是关闭不了 |