Re: Shortest code for Sub FileExists and DirExists
- From: "BeastFish" <no@xxxxxxxx>
- Date: Thu, 25 Oct 2007 09:34:29 -0400
Please also suggest a similar simple way for checking if I can
write to a file if it exists, and if it does not exist, I should check
if I can create one in a certain folder and write into it. My old
stupid way is to try to do it, and see if I can (Err = 53, etc.)
Not stupid at all. Errors aren't necessarily bad... in many cases (such as
file stuff), just think of them as information. Trapping the error such as
your example is a common way of doing it. Easy way to tell if an error is
information or bad... if you expect a particular line of code might generate
an error depending on external circumstance (such as file stuff), it's
information :-)
Changing it to boolean would affect the calling code but if
you're gonna fix it then I'd suggest fixing it right ;-)
This is no problem at all. It is used in a dozen places, but with F3
it is easy to locate all of them.
I guess I could also do
FileExists = CInt(FileLen(FileName1) > 0)
which should result in 0 if the file is not there.
A boolean return is "self documenting", i.e. it won't be confusing if you
need to sift through the code a year from now. It's also kinda common
sensical... Yes or no, true or false.
.
- Follow-Ups:
- Re: Shortest code for Sub FileExists and DirExists
- From: Steve Gerrard
- Re: Shortest code for Sub FileExists and DirExists
- References:
- Shortest code for Sub FileExists and DirExists
- From: beginner
- Re: Shortest code for Sub FileExists and DirExists
- From: Jan Hyde (VB MVP)
- Re: Shortest code for Sub FileExists and DirExists
- From: beginner
- Shortest code for Sub FileExists and DirExists
- Prev by Date: Re: one dimesion array - alternating sequence of data
- Next by Date: Re: Shortest code for Sub FileExists and DirExists
- Previous by thread: Re: Shortest code for Sub FileExists and DirExists
- Next by thread: Re: Shortest code for Sub FileExists and DirExists
- Index(es):
Relevant Pages
|