Re: MKDir not working



> >> 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

.



Relevant Pages

  • Manual Calc in a loop issue
    ... cells no longer visually update ... Even if the above occurs the loop seems to continue normally in the ... Sub TestManCalc() ... Static bWarned As Boolean ...
    (microsoft.public.excel.programming)
  • Re: Out of control threads
    ... This eliminates the boolean variable, which may be what is keeping the ... The sub waits in a loop for these threads to finish ... The end of the sub thread's sub sets a boolean ...
    (microsoft.public.dotnet.framework)
  • Re: do ... until loop issue
    ... Sub WorksheetC() ... Dim cellVal As Boolean ... Loop ...
    (microsoft.public.excel.programming)
  • Re: ERROR IN LOOP????
    ... Anyway, your code declares a sub that contains a loop, however your code ... > Dim test As Boolean, ...
    (microsoft.public.scripting.wsh)
  • Re: A little challenge for relativists.
    ... The Moon is 1.2 light seconds from Earth, ... > Dim redfirst As Boolean, bluefirst As Boolean, bluesecond As ... > Private Sub Command1_Click ...
    (sci.physics.relativity)

Loading