Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help with Recursive Call?
Hi.
I am familiar with what a recursive call is, but am still working on getting good at them. I'm trying to use the filesystemobject to create a directory, which may be several levels down from the existing directories. for instance, if I want to create the directory c:\Joe2\Level1\Level2\Level3 , but the current directory structure only has c:\Joe2 , I would like it to receive c:\Joe2\Level1\Level2\Level3 as the directory to create, and check for / create directories recursively, until it finds that the first directory in that string that exists is c:\Joe2 Then, create the three subdirectories recursively. The code I have works its way down and created the c:\Joe2\Level1 directory, but does not work it's way back up creating the other directories. And besides, I suspect my code is more complicated than it needs to be. Could someone help me with the code below? Thanks. ****************** Sub testdir() sbCreateFolder ("c:\Joe2\Level1\Level2\Level3") End Sub Sub sbCreateFolder(ByVal stFolder As String) 'dimension variables On Error Resume Next Dim fs As Object 'assign variables Set fs = CreateObject("Scripting.FileSystemObject") 'check if dest directory exists fs.createfolder (stFolder) If Not fs.folderexists(stFolder) Then While Right(stFolder, 1) < "\" stFolder = Left(stFolder, Len(stFolder) - 1) Wend stFolder = Left(stFolder, Len(stFolder) - 1) sbCreateFolder (stFolder) Else Exit Sub End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Recursive Functions...maybe | Excel Worksheet Functions | |||
Recursive Functio help | Excel Worksheet Functions | |||
Why doesn't this recursive function return the right value? | Excel Programming | |||
recursive sums | Excel Worksheet Functions | |||
Recursive Subs? | Excel Programming |