Re: Shortest code for Sub FileExists and DirExists



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.


.



Relevant Pages

  • Re: Create a writable folder in aspnet setup project
    ... I don't know whether this qualifies as clever or stupid, ... a cacls command from my custom install action in order ... >> change permisisons on a file object. ... Use the same method for folder. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Create a writable folder in aspnet setup project
    ... I don't know whether this qualifies as clever or stupid, ... a cacls command from my custom install action in order ... >> change permisisons on a file object. ... Use the same method for folder. ...
    (microsoft.public.dotnet.general)
  • Re: Clickonce deployment to local drive
    ... I've built an application in visual studio 2005 express and published ... several times and a new version appears in the folder and the setup ... obviously stupid things is that they are never obvious to the person ...
    (microsoft.public.dotnet.framework)
  • Re: Whoops on Delete Key
    ... I told her it was stupid, ... >Exchange MVP ... >> I accidentally wiped out the President of our company's ... >> deleted email folder. ...
    (microsoft.public.exchange2000.win2000)