469,127 Members | 1,440 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,127 developers. It's quick & easy.

Checking Text File is Already Opened

VijaySofist
107 100+
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

Expand|Select|Wrap|Line Numbers
  1. Public Function IsFileOpen(FileName As String) As Boolean
  2.     On Error GoTo ErrHandler
  3.     Open FileName For Binary Access Read Lock Read As #1
  4.         MsgBox Input$(LOF(1), #1)
  5.     Close #1
  6.     Exit Function
  7. ErrHandler:
  8.     MsgBox "File is Already Opened"
  9. End Function
  10.  

Can Any body give me the solution for this?

Thanks and Regards
Vijay. R
Aug 12 '08 #1
2 1226
joedeene
583 512MB
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
Aug 12 '08 #2
vdraceil
236 100+
u could copy the suspected file to a specific location and then try deleting that file(performing cut operation;cut=copy+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)
Aug 13 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by Materialised | last post: by
7 posts views Thread by emanshu | last post: by
13 posts views Thread by Tony Girgenti | last post: by
7 posts views Thread by CCLeasing | last post: by
7 posts views Thread by elnoire | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.