VB-Tec.de Visual Basic - Technik, FAQ, Tricks, BeispieleHome / System / Datei / SplitPath Dateipfad splitten |
Sub SplitPath(ByVal Fullpath As String, _
Optional ByRef Drive As String, _
Optional ByRef Path As String, _
Optional ByRef File As String, _
Optional ByRef Title As String, _
Optional ByRef Suffix As String)
Dim iPos As Long
'Laufwerk/Server bestimmen:
If Mid$(Fullpath, 2, 1) = ":" Then 'Laufwerk:
Drive = Left$(Fullpath, 2)
Fullpath = Mid$(Fullpath, 3)
ElseIf Left$(Fullpath, 2) = "\\" Then 'Server:
iPos = InStr(3, Fullpath, "\")
Drive = Left$(Fullpath, iPos - 1)
Fullpath = Mid$(Fullpath, iPos)
End If
'Pfad und Datei trennen:
For iPos = Len(Fullpath) To 1 Step -1
If Mid$(Fullpath, iPos, 1) = "\" Then Exit For
Next iPos
Path = Left$(Fullpath, iPos)
File = Mid$(Fullpath, iPos + 1)
'Dateiname und Suffix trennen:
For iPos = Len(File) To 1 Step -1
If Mid$(File, iPos, 1) = "." Then Exit For
Next iPos
If iPos Then
Title = Left$(File, iPos - 1)
Suffix = Mid$(File, iPos + 1)
Else
Title = File
Suffix = ""
End If
End Sub
Beispielsweise gibt das StatementSplitPath "C:\Temp\Test\abc.xyz.txt", sLW, sPfad, sDatei, sName, sSuffixdie Werte sLW="C:", sPfad="\Temp\Test\", sDatei="abc.xyz.txt", sName="abc.xyz" und sSuffix="txt" zurück.
© Jost Schwider, 27.07.2000-02.11.2000 - http://vb-tec.de/dateipfa.htm