If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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.