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.
I am using XP pro.
FileOpen(1, fnap_file_name_and_path, OpenMode.Input, , OpenShare.LockReadWrite)
Any help appreciated.