Checking Text File is Already Opened

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    Checking Text File is Already Opened

    Hi All!

    I want to check whether a given text File is Already Opened or not. I am using Visual Basic 6.0 in the Windows XP OS.

    I am using the following code. It works for .doc, .xls and .mdb. But its not working for .txt file type

    Code:
    Public Function IsFileOpen(FileName As String) As Boolean
        On Error GoTo ErrHandler
        Open FileName For Binary Access Read Lock Read As #1
            MsgBox Input$(LOF(1), #1)
        Close #1
        Exit Function
    ErrHandler:
        MsgBox "File is Already Opened"
    End Function

    Can Any body give me the solution for this?

    Thanks and Regards
    Vijay. R
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    you could do a try, catch block to open a file with all access, like use the filestream, and set the shared propertie to fileshare.none, and if it is being used it should throw an exception

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      u could copy the suspected file to a specific location and then try deleting that file(performing cut operation;cut=c opy+delete)..
      any open file will throw an error which u can identify,thus knowing whether the file is open or not.
      this method works for almost all files like .doc,.mp3,.wav. ...
      but not to text files.
      text files can be deleted even while it is running(in a notepad)

      Comment

      Working...