Tipp 1.14 - Kurzen Dateipfad ermitteln

Wie kann ich den kurzen (DOS) Dateipfad ermitteln?

Mit dieser Funktion können Sie den kurzen (DOS) Dateipfad ermitteln. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.

Api-AufrufeVerwendete Win32-Api-Aufrufe und Typen: GetShortPathName

Beispiel:

Option Explicit
 
Public Declare Function GetShortPathName _
    Lib "kernel32" Alias _
    "GetShortPathNameA" _
    (ByVal lpszLongPath As String, _
    ByVal lpszShortPath As String, _
    ByVal cchBuffer As Long) As Long
 
Public Function GetShortPath( _
                ByVal sLongPath As String) _
                As String
  '// -----------------------------------------------------
  '// Methode:   | Ermittelt den 8.3 (DOS)-Pfad
  '// -----------------------------------------------------
  '// Parameter: | sLongPath = gültiger Datei-/Ordnerpfad
  '// -----------------------------------------------------
  '// Rückgabe:  | 8.3 (DOS)-Pfad
  '// -----------------------------------------------------
  '// Autor:     | Stefan Kulpa
  '//            | EDV Innovation & Consulting - Dormagen
  '// -----------------------------------------------------
 
  Dim sShortPath  As String
  sShortPath = VBA.String(260, 0)
  If GetShortPathName(sLongPath, _
                      sShortPath, Len(sShortPath)) Then
    GetShortPath = _
        VBA.Left(sShortPath, _
                 VBA.InStr(sShortPath, vbNullChar) - 1)
  End If
 
End Function