This function is used in conjunction with the CopyTree
function and returns the lowest level (most nested) folder when passed a full file path.
This is achieved by searching for the leading backslash to determine the immediate folder
name. Add the following code to a FileHandling.bas standard module to compile a File
Utility function set:Public Function GetFolderName(FilPath As String) As String
'*************************************************************
'<DESC> Retrieves the lowest level folder name from
' filepath.</DESC>
'<RETURN> String:
' Folder name</RETURN>
'<ACCESS> Public</ACCESS>
'<ARGS> FullPath:
' Full Filepath</ARGS>
'<USAGE> DirPath$ = GetFolderName("c:/winnt/system/")
' </USAGE>
'*************************************************************
Dim strTemp As String
Dim strChar As String
Dim intCounter As Integer
If Right$(FilPath, 1) = "\" Then
strTemp = Left$(FilPath, Len(FilPath) - 1)
Else
strTemp = FilPath
End If
GetFolderName = "Error"
For intCounter = Len(strTemp) To 1 Step -1
strChar = Mid$(strTemp, intCounter, 1)
If strChar = "\" Then
GetFolderName = Mid$(strTemp, intCounter + 1)
Exit For
End If
Next intCounter
End Function
|