TC said:
My only concern with that, would be that you don't check why the error
occurred. Perhaps the folder didn't exist, but you couldn't create it
because of a permissions problem. In that case, the code should fail
with a trappable runtime error IMHO.
I agree with you. That's why I usually use the pants-and-suspenders approach
of trying to add the folders, and then double-check that the target exists
before I try using it. For instance, I'll have a function that returns the
path of the folder to use, but I'll check that the path exists before trying
to use it.
I assumed that dir$() could check for folders, but apparently not :-(
It can. You just need to pass the correct parameter. I've got a folder named
Local on my C: drive. Here's the results of running Dir with different
configurations:
?Dir("C:\Local")
?Len(Dir("C:\Local"))
0
?Dir("C:\Local", vbDirectory)
Local
?Dir("C:\Local\")
?Len(Dir("C:\Local\"))
0
?Dir("C:\Local\", vbDirectory)
..
(in case it's not obvious, that's a period returned by the last call)