Manage Learn to apply best practices and optimize your operations.

Directory Generator Function (This One Really Works!)

There have been a few attempts in the past to write a directory generator in the past. Most of them are too limited or just don't work.

This little bit of code lets you pass a string (which is a directory path from the root) and will generate all the directories as needed. It can handle partial or non-existent directory paths. Please try it. Please Submit any improvements to me.


Sub CheckForCreateDirectory(FullPath As String)
' Given a complete directory path including the root directory, (eg h:wordtemplatesfaxes), this function will create all directories in a path as requried.
' Also, if a partial path exists it will follow it and create subdirectories as needed.
'By Giulio Campobassi, ASIC,, October 2000.

Dim iStartPos As Integer
Dim iEndPosCurDir As Integer
Dim iEndPosSubDir As Integer
Dim strSubDir As String
Dim strCurDir As String
Dim strFName As String
Dim strNewSubDir As String
Dim iSubDirFound As Integer
Dim iSubDirLength As Integer
Dim iDirCreated As Integer
Dim iOffset As Integer
Dim Continue As Integer

iStartPos = 1
' Start at the root
iEndPosCurDir = Instr(FullPath, "")
strCurDir = Mid$(FullPath, iStartPos, iEndPosCurDir)
iDirCreated = False
' get all the files in the starting directory
strFName = Dir(strCurDir,16)
continue = True
While strFName <> "" Or continue
iSubDirFound = False
If Mid(FullPath, iEndPosCurDir + 1,1) = "" Then
iOffset = 2
iOffset = 1
End If
' get the subdirectory
strSubDir = getSubDir(FullPath, iEndPosCurDir + iOffset)
If Trim(strSubDir) = "" Then
' if at the end of the list then exit
If iEndPosCurDir < Len(fullpath) Then
strSubDir = Mid(FullPath, iEndPosCurDir + iOffset, Len(fullPath) - iEndPosCurDir + iOffset)
Exit Sub
End If
End If
' Branch here if a directory has been created at any time
If Not iDirCreated Then
While strFName <> "" And Not iSubDirFound
If Ucase(strFName) = Ucase(strSubDir) Then
iSubDirFound = True
End If
If Not iSubDirFound Then
strFName = Dir$()
End If
If Mid(strCurDir,Len(strCurDir),1) = "" Then
strNewSubDir = strCurDir + strSubDir
strNewSubDir = strCurDir + "" + strSubDir
End If

strCurDir = strNewSubDir
If Not iSubDirFound Then
iDirCreated = True
strFName = Dir$(strCurDir + "*.*", 16)
End If

If Trim(strSubDir) <> "" Then
strNewSubDir = strCurDir + "" + strSubDir
strCurDir = strNewSubDir
continue = False
End If
End If
iEndPosCurDir = Len(strCurDir)
End Sub


Dig Deeper on Domino Resources - Part 3

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...