472,111 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

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 1302
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.