Re: MKDir not working
- From: "Rick Rothstein" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Wed, 22 Jun 2005 00:54:30 -0400
> >> Submitted by Frederick Rothstein, Trenton, New Jersey
> >
> > Hey... that's me! My real name is Frederick and since they were
paying
> > $25 (I think) per tip back then, I used my real name so it would be
> > used on the check.
>
> Wow, and here the first response I expected to that was a one-liner
using Split! <g>
Split you say? How about Split and Reverse both?
Public Sub MkDirs(ByVal PathIn As String)
Dim X As Long
If Right$(PathIn, 1) <> "\" Then PathIn = PathIn & "\"
On Error Resume Next
For X = 3 To UBound(Split(PathIn, "\")) + 1
MkDir Replace(PathIn, Split(PathIn, "\", X)(X - 1), "")
Next
End Sub
Yeah, I know... it's not a one-liner, but there IS only one active
statement in the loop. The opening If statement could be eliminated by
concatenating an IIf function call into both the first argument of the
Split function in the upper limit expression of For statement and the
first argument of the Split function in the active loop statement; but I
thought that was would be carrying the minimal code thing too far, so I
created a separate line for it. As for the On Error statement... we
can't escape using that if we want the function to work at all. So, no
one-liner. Oh, and I guess you noticed the function became a Sub along
the way... that was to save two extra lines which would be needed to
track and return a Boolean status from the function. For the purists out
there who insist this be a function, here is what I think is the minimal
code (the If statement previously explained notwithstanding) that should
work...
Public Function MkDirs(ByVal PathIn As String) As Variant
Dim X As Long
If Right$(PathIn, 1) <> "\" Then PathIn = PathIn & "\"
On Error Resume Next
For X = 3 To UBound(Split(PathIn, "\")) + 1
MkDir Replace(PathIn, Split(PathIn, "\", X)(X - 1), "")
MkDirs = MkDirs + Err.Number
Next
MkDirs = Not CBool(MkDirs Mod 75)
End Function
Please note, by the way, that the function returns a Variant with a
sub-type of Boolean (I needed to use the function name for addition
within the loop before setting it to a Boolean return value in order to
minimize the number of lines of code.<g>
Oh, one last thing... anyone not in on the OneLiner-Split-Reverse joke
involving my more "creative" postings...
DON'T USE THE CODE POSTED HERE!!!
If you do, your teacher will flunk you, or your boss will fire you...
that's a guarantee.<g>
Rick
.
- Follow-Ups:
- Re: MKDir not working
- From: Karl E. Peterson
- Re: MKDir not working
- References:
- MKDir not working
- From: David
- Re: MKDir not working
- From: Karl E. Peterson
- Re: MKDir not working
- From: Rick Rothstein
- Re: MKDir not working
- From: Karl E. Peterson
- MKDir not working
- Prev by Date: Re: Execute On Focus
- Next by Date: Re: MKDir not working
- Previous by thread: Re: MKDir not working
- Next by thread: Re: MKDir not working
- Index(es):
Relevant Pages
|
Loading