检测记事本打开的文件

编程入门 行业动态 更新时间:2024-10-26 14:34:37
本文介绍了检测记事本打开的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写了一个应用程序,警告试图打开 文件当前正在使用的文件的用户。它工作正常,除非记事本打开文件 。如果打开一个文本文件,大多数计算机都配置为默认情况下使用记事本打开文件,如果它们是 配置为默认使用记事本我想要它保持这种方式 而不是将文本检索到我的应用程序或强迫用户使用 另一个应用程序来读取文件。我正在使用以下代码我发现 online和lErrNum返回零值如果Notepad有文件 打开但是当大多数其他文件打开时返回70另一个 申请。 Don 打开sPathFile输入锁定读取为#iFileNum 关闭iFileNum lErrNum = Err.Number 错误GoTo 0 选择案例lErrNum 案例0''没有发生错误。文件尚未被另一个 用户打开。 FileIsOpen = False 案例70''错误编号为权限被拒绝。文件已由另一位用户打开 。 FileIsOpen = True 案例53''找不到文件 FileIsOpen = False Case Else''发生另一个错误。 FileIsOpen = True MsgBox错误(lErrNum) 结束选择

解决方案

记事本打开文件,将其加载到内存中,然后立即关闭。你可以单独打开文件,或者使用FindFirstChangeNotification()查看 如果用户编辑并将文件保存到你的进程之外,然后提示 用户,如果他想重新加载文件。请参阅此VB6示例: http:/ /vbnet.mvps/code/fileapi/watchedfolder.htm blockquote>

感谢您的回复,但我需要一些东西检测到 文件当前是打开的。由于文件在 之后立即关闭,正如你所描述的那样阅读内容,这听起来像我在问什么。 是不可能的。我试图阻止用户同时打开文件 ,并且做出更改时不知道两个或更多人 正在进行可能发生冲突的更改。我能想到的每一种方法都不会检测到文件是否打开以防止出现问题或者检测到b / b 为什么在为时已晚而无法阻止它。 Don 2008年9月13日星期六14:10:09 -0400,expvb < no **** @ coxwrote:

>记事本打开文件,将其加载到内存中,然后立即关闭。您可以独占打开文件,或使用FindFirstChangeNotification()查看用户是否编辑并将文件保存在进程外,然后提示用户是否要重新加载文件。请参阅此VB6示例: http:/ /vbnet.mvps/code/fileapi/watchedfolder.htm

ds ***** @ yahoo (唐)在新闻中写道:48 ************* @ news.west。 cox:

感谢您的回复,但我需要检测到 文件当前打开的内容。

1 但该文件目前尚未打开。它打开只有几毫秒 而记事本读取它然后立即再次关闭。

由于文件在 正如你所描述的那样阅读内容,这听起来像我在问什么 是不可能的。

这是正确的。

我试图阻止用户打开文件 同时进行更改并不知道两个或更多人 正在进行可能发生冲突的更改。我能想到的每种方法 要么不会检测到文件是开放的

转到1

I wrote an app that alerts a user who attempts to open a file that the file is currently in use. It works fine except when the file is opened by Notepad. If a text file is opened, most computers are configured to use Notepad to open the file by default and if they are configured to use Notepad by default I want it to remain that way rather than retrieve the text into my app or force the user to use another app to read the file. I''m using the following code I found online and lErrNum returns a value of zero if Notepad has the file open but returns 70 when most other files are open using another application. Don Open sPathFile For Input Lock Read As #iFileNum Close iFileNum lErrNum = Err.Number On Error GoTo 0 Select Case lErrNum Case 0 ''No error occurred. File is NOT already open by another user. FileIsOpen = False Case 70 ''Error number for "Permission Denied." File is already opened by another user. FileIsOpen = True Case 53 ''File not found FileIsOpen = False Case Else ''Another error occurred. FileIsOpen = True MsgBox Error(lErrNum) End Select

解决方案

Notepad opens the file, load it in memory, then close it immediately. You can open the file exclusively, or use FindFirstChangeNotification() to see if the user edited and saved the file outside your process, then prompt the user if he wants to reload the file. See this VB6 sample: vbnet.mvps/code/fileapi/watchedfolder.htm

Thanks for the response, but I need something that detects that the file is currently open. Since the file is immediately closed after reading the contents as you described, it sounds like what I''m asking isn''t possible. I''m trying to prevent users from having the file open at the same time and making changes not aware that two or more people are making changes that might conflict. Every method I can think of either won''t detect the file is open preventing the problem or detects that a change was made after it was too late to prevent it. Don On Sat, 13 Sep 2008 14:10:09 -0400, "expvb" <no****@coxwrote:

>Notepad opens the file, load it in memory, then close it immediately. Youcan open the file exclusively, or use FindFirstChangeNotification() to seeif the user edited and saved the file outside your process, then prompt theuser if he wants to reload the file. See this VB6 sample:vbnet.mvps/code/fileapi/watchedfolder.htm

ds*****@yahoo (Don) wrote in news:48*************@news.west.cox:

Thanks for the response, but I need something that detects that the file is currently open.

1 But the file is NOT currently open. It is opened only for milliseconds while Notepad reads it then is closed again immediately.

Since the file is immediately closed after reading the contents as you described, it sounds like what I''m asking isn''t possible.

That is correct.

I''m trying to prevent users from having the file open at the same time and making changes not aware that two or more people are making changes that might conflict. Every method I can think of either won''t detect the file is open

Goto 1

更多推荐

检测记事本打开的文件

本文发布于:2023-11-11 11:04:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:记事本   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!