Public Enum PathReturn
FileExtension = 0 PathOnly = 1 DriveLetter = 2 DriveAndPath = 3 FileName = 4 PathAndFileName = 5 End Enum Public Function PathSplit(thePath As String, _ ReturnVal As PathReturn) As String Dim sDriveLetter As String Dim sFileName As String Dim sFileExtension As String Dim inCounter As Integer Dim inFoundPos As Integer Dim thePathNoFileName As String If Len(thePath) = 0 Then Exit Function inCounter = Len(thePath) inFoundPos = InStrRev(thePath, "\", inCounter) sFileName = Mid$(thePath, inFoundPos + 1, inCounter - inFoundPos) inFoundPos = InStrRev(thePath, ".", inCounter) sFileExtension = Mid$(thePath, inFoundPos + 1, inCounter _ - inFoundPos) If Mid(thePath, 2, 1) = ":" Then sDriveLetter = Left(thePath, 2) thePath = Mid(thePath, 3) thePathNoFileName = Mid(thePath, 1, Len(thePath) - _ Len(sFileName)) End If Select Case ReturnVal Case 0: PathSplit = sFileExtension Case 1: PathSplit = thePathNoFileName Case 2: PathSplit = sDriveLetter Case 3: PathSplit = sDriveLetter & thePathNoFileName Case 4: PathSplit = sFileName Case 5: PathSplit = thePath End Select End Function Inputs: 1. String with path Example:"C:\test\test.txt" or control With the path Example: text1.txt 2. Enum For the various sections of the path Returns:This function returns a String Assumes:This is a very useful but extremely basic function. There should be no problems whatsoever. just copy and paste into a BAS module and call the Function from a form. |