473,503 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is a txt file Read-Only?

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
8 1761
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
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
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
Thank you, Gentlemen.

Jan 9 '06 #5
Thank you, Gentlemen.

Jan 9 '06 #6
Lyle Fairfield should have written:
Public Function DoesFileExist1997(ByVal FilePath As String) As Boolean
Const FileNotFoundErrNumber As Long = 53
....

Jan 9 '06 #7
Thankyou Gentlemen.

Karl

Jan 9 '06 #8
No, not obsessive . Kept getting server errors when posting my reply.

Jan 9 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
11443
by: Paul | last post by:
Hello, I've been reading up on security in Java Applets and whilst I understand the concept, I can't successfully get my applet to read a file on my local machine. I discovered from...
2
2530
by: Brian Ward | last post by:
First: sorry as a relative newbie for previously not including code. My question: Reading C++ books I almost always find programs such as the one below give the following type of code for reading...
1
3586
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
3
2692
by: Abhas | last post by:
> > Hi, this is Abhas, > > I had made a video library program in C++, but was facing a problem. > > After entering 12 movies, i cannot enter any more movies. > > Something gibberish comes instead....
8
1773
by: siliconwafer | last post by:
Hi All, If I open a binary file in text mode and use text functions to read it then will I be reading numbers as characters or actual values? What if I open a text file and read it using binary...
3
2135
by: Wijaya Edward | last post by:
Hi, How can we slurp all content of a single file into one variable? I tried this: <open file 'somefile.txt', mode 'r' at 0xb7f532e0>
5
3282
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
0
5750
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
3
8210
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
15
9412
by: patf | last post by:
Hi - experienced programmer but this is my first Python program. This URL will retrieve an excel spreadsheet containing (that day's) msci stock index returns. ...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.