现在的位置: 首页 > 综合 > 正文

如何检查文件正在被使用

2013年05月31日 ⁄ 综合 ⁄ 共 1159字 ⁄ 字号 评论关闭

from

http://www.eggheadcafe.com/software/aspnet/31943038/check-file-opened-or-not.aspx

check file opened or not?

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

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.

http://msdn2.microsoft.com/en-us/library/aa914735.aspx

Any comments?

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

Pass 0 to dwShareMode and you disallow sharing.

--
SvenC

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



抱歉!评论已关闭.