Testing a file to see if it is already open in vb2008


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Testing a file to see if it is already open in vb2008

  1. #1
    Join Date
    Jul 2007
    Posts
    139

    Testing a file to see if it is already open in vb2008

    I want to make changes to a file but only if it is not in use by another program.

    I have seen several things on the net that all suggest I should

    a) see if the file exists.
    b) Try to rename it. If I can it is not open and I should rename it back and proceed. If I canít then another program has it open.


    This seems logical but when I try it doesnít work.

    I have confirmed that is an error in the approach, rather than in code because if I find a program in windows explorer and rename it I can. If I open the file in, say , notepad I can still rename the file in windows explorer! When I save the file in notepad it just creates a copy of the file with the original name.


    I have also tried locking the file hoping that it would generate an error if it tried to lock a file that was already open.
    Code:
    try
    
         FileOpen(1, fnap_file_name_and_path, OpenMode.Input, , OpenShare.LockReadWrite)
                    FileClose(1)
                Catch
                    MessageBox.Show("error")
    
                End Try
    I am using XP pro.

    Any help appreciated.

    Thanks,

    Steve,

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Jul 2007
    Posts
    139
    Thanks alot,

    I,m working on something esle at the moment but I'll have a look when I come back to it.

    Steve

Similar Threads

  1. Replies: 1
    Last Post: 04-17-2006, 01:20 AM
  2. Replies: 1
    Last Post: 01-28-2006, 06:59 AM
  3. Test a file to see if it's open
    By JohnN in forum VB Classic
    Replies: 12
    Last Post: 05-08-2001, 04:25 PM
  4. open text file using shell
    By Hian Chew in forum VB Classic
    Replies: 0
    Last Post: 03-06-2001, 12:28 PM
  5. Replies: 0
    Last Post: 12-19-2000, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center