Article ID: 113897
Article Last Modified on 12/9/2003
Sub Command1_Click ()
TempPath$ = Text1
DriveLetter = ""
DirPath = ""
Filename = ""
Extension = ""
If Mid(TempPath$, 2, 1) = ":" Then ' Find the drive letter.
DriveLetter = Left(TempPath$, 2)
TempPath$ = Mid(TempPath$, 3)
End If
PathLength% = Len(TempPath$)
For OffSet% = PathLength% To 1 Step -1 ' Find the next delimiter.
Select Case Mid(TempPath$, OffSet%, 1)
Case ".": ' This indicates either an extension or a . or a ..
ThisLength% = Len(TempPath$) - OffSet%
If ThisLength% >= 1 And ThisLength% <= 3 Then ' Extension
Extension = Mid$(TempPath$, OffSet%, ThisLength% + 1)
End If
TempPath$ = Left(TempPath$, OffSet% - 1)
Case "\": ' This indicates a path delimiter.
ThisLength% = Len(TempPath$) - OffSet%
If ThisLength% >= 1 And ThisLength% <= 8 Then ' Filename
Filename = Mid$(TempPath$, OffSet% + 1, ThisLength%)
TempPath$ = Left(TempPath$, OffSet%)
FileNameFound% = True
Exit For
End If
Case Else
End Select
Next OffSet%
If FileNameFound% = False Then
Filename = TempPath$
Else
DirPath = TempPath$
End If
' Print to form for display.
Form1.Cls
Form1.Print "Drive:", DriveLetter
Form1.Print "Path:", DirPath
Form1.Print "Filename:", Filename
Form1.Print "Extension:", Extension
End Sub
Additional query words: 1.00 2.00 3.00 dissect parse break apart
Keywords: KB113897