如何检查文件正在被使用

时间:2025-02-12 07:11:15
How about using OpenFile() with OF_SHARE_EXCLUSIVE? I think it is better
since using CreateFile, if successful, I have to delete the file, and my
purpose is only to check whether some file is opened (used) or not.

=========================================================
Hi Victor,


How about using OpenFile() with OF_SHARE_EXCLUSIVE? If successful, I need to
close the file.


regards,


=========================================================
Hi George,

Please *read the complete* documentation: you can call CreateFile in a way
that it will only open a file if it already exists, so that no file is
created.

=========================================================

Thanks SvenC,


For CreateFile, it only has option OPEN_EXISTING to check whether a file is
existing or not, but no exclusive mode checking to see whether the existing
file is used (opened) by any other thread/process.

/en-us/library/

Any comments?

=========================================================
Hi George,

Pass 0 to dwShareMode and you disallow sharing.

--
SvenC

=========================================================