By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Is a txt file Read-Only?

P: n/a
No, not a cross-post. I posted to the wrong group first up.

Hi all,
Using Len(Dir$(txtFileName)) to check if a file exists, can anyone
suggest an additional step to check the Read-Only status of the same
file?
Thanks in advance.
Karl

Jan 7 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi Karl

Could you try opening the file in Append mode?

That should fail with a trappable error if the file is read-only, without
destroying what is in the file.

Example:
Open "C:\MyFile.txt" For Append As #1
Close #1
'Now keep going if the Open statement did not cause an error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Karl" <ka******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

Using Len(Dir$(txtFileName)) to check if a file exists, can anyone
suggest an additional step to check the Read-Only status of the same
file?

Thanks in advance.

Karl

Jan 7 '06 #2

P: n/a
Karl wrote:
Using Len(Dir$(txtFileName)) to check if a file exists, can anyone
suggest an additional step to check the Read-Only status of the same
file?


Function GetAttr(PathName As String) As VbFileAttribute

VbFileAttributes are:

vbNormal

vbReadOnly

vbHidden

vbSystem

vbVolume

vbDirectory

vbArchive

These are all bit values and can be or-ed safely.

This is an OLD function I have used to check for file existence:

Public Function DoesFileExist1997(ByVal FilePath As String) As Boolean
Private Const FileNotFoundErrNumber As Long = 53
On Error GoTo DoesFileExist1997Err
GetAttr FilePath
DoesFileExist1997 = True
DoesFileExist1997Exit:
Exit Function
DoesFileExist1997Err:
With Err
If .Number = FileNotFoundErrNumber Then
DoesFileExist1997 = False
Else
MsgBox .Description, vbCritical, "Error Number: " & .Number
End If
End With
Resume DoesFileExist1997Exit
End Function
--
Lyle Fairfield
Jan 7 '06 #3

P: n/a
blnReadOnly = ((GetAttr(txtFileName) AND vbReadOnly) = vbReadOnly)

--
Terry Kreft

"Karl" <ka******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
No, not a cross-post. I posted to the wrong group first up.

Hi all,
Using Len(Dir$(txtFileName)) to check if a file exists, can anyone
suggest an additional step to check the Read-Only status of the same
file?
Thanks in advance.
Karl

Jan 7 '06 #4

P: n/a
Thank you, Gentlemen.

Jan 9 '06 #5

P: n/a
Thank you, Gentlemen.

Jan 9 '06 #6

P: n/a
Lyle Fairfield should have written:
Public Function DoesFileExist1997(ByVal FilePath As String) As Boolean
Const FileNotFoundErrNumber As Long = 53
....

Jan 9 '06 #7

P: n/a
Thankyou Gentlemen.

Karl

Jan 9 '06 #8

P: n/a
No, not obsessive . Kept getting server errors when posting my reply.

Jan 9 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.