LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default kept working, got it working, but...

Thank you!

I was looking for that text compare, but didn't find it today. Thank you
for pointing it out. It definitely cleans up the part of the code that finds
the current directory's parent directory, A LOT.

Thank you for your constructive comments! I do appreciate it.
Mark


"JMB" wrote:

Recursion is usually less efficient than an iterative loop due the overhead
of extra procedure calls. Also, if it gets out of hand, it can consume all
of the computers memory or cause stack overflow errors.

The first function uses as few lines of code as I could (just as an
example). The second tests to see if the folder exists before making another
procedure call (which would be more efficient)


Function jCreateFolder(ByVal stFolder As String) As Boolean
On Error Resume Next
jCreateFolder (Left(stFolder, _
InStrRev(stFolder, "\", -1, vbTextCompare) - 1))
MkDir (stFolder)
End Function


Function jCreateFolder(ByVal stFolder As String) As Boolean
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
If Not FSO.folderexists(stFolder) Then _
jCreateFolder (Left(stFolder, _
InStrRev(stFolder, "\", -1, vbTextCompare) - 1))
MkDir (stFolder)
End Function



"mark" wrote:

I kept working, and got it working, but I still suspect it's more complicated
than it needs to be.

Here's what I have:

******************
Sub testdir()

Dim blFolder As Boolean

blFolder = fnCreateFolder("c:\Joe2\Level1\Level2\Level3")


End Sub

Function fnCreateFolder(ByVal stFolder As String) As Boolean

'dimension variables
On Error Resume Next
Dim fs As Object
Dim stFolderTest As String

'assign variables

Set fs = CreateObject("Scripting.FileSystemObject")
stFolderTest = stFolder

'check if dest directory exists



While Not fs.folderexists(stFolder)

fs.createfolder (stFolder)

If fs.folderexists(stFolder) Then


fnCreateFolder = True

Else

While Right(stFolderTest, 1) < "\"

stFolderTest = Left(stFolderTest, Len(stFolderTest) - 1)

Wend

stFolderTest = Left(stFolderTest, Len(stFolderTest) - 1)
fnCreateFolder (stFolderTest)

End If

Wend

End Function

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive Functions...maybe busboy10 Excel Worksheet Functions 0 March 28th 11 09:46 PM
Recursive Functio help BigBobbo Excel Worksheet Functions 1 May 10th 06 07:23 PM
Why doesn't this recursive function return the right value? RB Smissaert Excel Programming 10 September 3rd 05 01:11 AM
recursive sums Joe Excel Worksheet Functions 6 July 17th 05 09:45 AM
Recursive Subs? ExcelMonkey[_74_] Excel Programming 5 February 5th 04 02:54 AM


All times are GMT +1. The time now is 09:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"