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.

Giulio

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, giulio.campobassi@asic.gov.au, 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
Else
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)
Else
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
Wend
If Mid(strCurDir,Len(strCurDir),1) = "" Then
strNewSubDir = strCurDir + strSubDir
Else
strNewSubDir = strCurDir + "" + strSubDir
End If

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

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

 

This was first published in November 2000

Dig deeper on Domino Resources - Part 3

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close