Question Checking if a file is Read Only

bathyphen

Member
Joined
Aug 19, 2011
Messages
11
Programming Experience
5-10
I have got the following code to check whether a file is open or not as I want to ignore it if it is, but it doesnt seem to be working. Can anyone help?
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]IF I[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]O.File.GetAttributes(f) [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000] IO.FileAttributes.ReadOnly) = IO.FileAttributes.ReadOnly [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE]
 
File access and file attributes are two different things. You can use the FileStream Class (System.IO) and request open for different access and share modes to see if it would be available. Usually if a file is opened for writing it would not allow subsequent write access, but often allow reading. Usually if a file is open only for reading it will allow others to read as well.
 
Thank you for the reply.

Totally appreciate the difference, was getting confused on explaining as it was giving me a 'Do you want to open as Read Only' message when I opened it, which lead to me asking the wrong question.

I have amended the code that I linked to on my previous post and it's now working fine.

Thank you again, for your help :)
 
Back
Top