Create directory paths

Want to create a directory on a file system? These 2 functions will do the trick. You must pass the complete path of the directory you want to create (ie. c:tempsub1sub2 ). It can be either a partial or completely non-existent path. Try it!!


 Sub CreateDirectory(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 sub-directories as needed ' By Giulio Campobassi, 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 Function getSubDir(strFullPATH As String, iStartPos As Integer) As String Dim iEndPos As Integer Dim iSubDirLength As Integer getSubDir = "" If iStartPos < Len(strFullPath) Then iEndPos = Instr(iStartPos, strFullPath, "") If iEndPos > 0 Then iSubDirLength = iEndPos - iStartPos getSubDir = Mid$(strFullPath, iStartPos, iSubDirLength) End If End If End Function
This was first published in April 2001

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