1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

Problemstellung:

Wie kann ich einen kompletten Dateipfad in Laufwerk, Pfad, Dateinamen und Extension zerlegen? 

Public Type SPLITPATH
    sDrive As String
    sPath   As String
    sFile     As String
    sExt As String
End Type
Public Function fileSplit(ByVal sFilePath As String) As SPLITPATH
' die Prozedur zerlegt den Dateinamen sFilePath in LW, Path, Name, Extension
Dim I As Integer
With fileSplit
    If Mid$(sFilePath, 2, 1) = ":" Then
        .sDrive = Left$(sFilePath, 2)
        sFilePath = Mid$(sFilePath, 3)
    End If
     For I = Len(sFilePath) To 1 Step -1
        If Mid(sFilePath, I, 1) = "\" Then  ' keine Extension vorhanden
            .sExt = ""
            Exit For
        End If
        If Mid(sFilePath, I, 1) = "." Then
            .sExt = Right(sFilePath, Len(sFilePath) - I)
            sFilePath = Left(sFilePath, I - 1)
            Exit For
        End If
     Next I
     I = Len(sFilePath)
     If InStr(sFilePath, "\") <> 0 Then
        While Mid(sFilePath, I, 1) <> "\"
            I = I - 1
        Wend
     End If
     .sPath = Left(sFilePath, I)
     .sFile = Right(sFilePath, Len(sFilePath) - I)
 End With
End Function

Aufruf:

Dim tSplitPath As SPLITPATH
tSplitPath = fileSplit("I:\Downloads\DB Serienbrief\DB Serienbrief.mdb")

tSplitPath.sDrive = "I:"
tSplitPath.sPath = "\Downloads\DB Serienbrief\"
tSplitPath.sFile = "
DB Serienbrief"
tSplitPath.sExt = "mdb"

 

Ähnliche Artikel

Kommentar schreiben

Sicherheitscode
Aktualisieren

Login Form

1.png1.png9.png3.png2.png6.png5.png
Heute81
Gestern57
Diese Woche194
Dieser Monat1324
Total1193265

  • IP: 54.80.81.223
  • Browser: Unknown
  • Version:
  • OS: Unknown

Online

1
Online

23. Mai 2018