LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default 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
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 08:34 PM.

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

About Us

"It's about Microsoft Excel"