RSS
StartseiteKnowledge LibraryTop 10Impressum

Dateisystem-Typ

Ermitteln, welches Dateisystem verwendet wird.

Man hat es heutzutage meist mit einer Vielzahl unterschiedlicher Dateisysteme, wie FAT, FAT32, NTFS und anderen zu tun. Mit einer kleinen Funktion, können Sie feststellen, mit welchem Dateisystem gearbeitet wird.

Heutzutage trifft man auf eine Vielzahl unterschiedlicher Dateisysteme, wie FAT, FAT32, NTFS und andere. Mit der API Funktion GetVolumeInformation, können Sie ermitteln, mit welchem Dateisystem gearbeitet wird. Zur einfacheren Anwendung, wird der Aufruf in der Funktion "FileSystemType" gekapselt. Als Parameter übergeben Sie den Pfad von dem Sie den Name des Dateisystems ermitteln möchten. Dabei ist es egal, ob dies ein lokaler Pfad oder ein UNC Pfad ist. Schlägt die Funktion fehl, wird ein abfangbarer Fehler ausgelöst:

Private Declare Function GetVolumeInformation Lib "kernel32" _
        Alias "GetVolumeInformationA" (_
        ByVal lpRootPathName As String, _
        ByVal lpVolumeNameBuffer As String, _
        ByVal nVolumeNameSize As Long, _
        ByRef lpVolumeSerialNumber As Long, _
        ByRef lpMaximumComponentLength As Long, 
        ByRef lpFileSystemFlags As Long, _
        ByVal lpFileSystemNameBuffer As String, _
        ByVal nFileSystemNameSize As Long _
              ) As Long

Private Const ERROR_PATH_NOT_FOUND As Long = 3&
Private Const ERROR_NOT_READY      As Long = 21&
Private Const ERROR_BAD_NETPATH    As Long = 53&

Public Function FileSystemType(ByVal RootPath As String) As String
  Dim lRet        As Long
  Dim lFileSystem As String
  Dim lSlashCount As Integer
  Dim lUNCRoot    As Long
    
  If Left$(RootPath, 2) <> "\\" Then
    RootPath = Left$(RootPath, 1) & ":\"
  Else
    If Right$(RootPath, 1) <> "\" Then
      RootPath = RootPath & "\"
    End If
    
    lUNCRoot = 2
    
    For lSlashCount = 1 To 2
      lUNCRoot = InStr(lUNCRoot + 1, RootPath, "\")
    Next
    
    If CBool(lUNCRoot) Then
      RootPath = Left$(RootPath, lUNCRoot)
    End If
  End If
  
  lFileSystem = Space$(16)
  lRet = GetVolumeInformation(RootPath, vbNullString, 0, 0, 0, 0, _
                              lFileSystem, Len(lFileSystem))
  
  If CBool(lRet) Then
    FileSystemType = Left$(lFileSystem, _
                           InStr(1, lFileSystem, vbNullChar) - 1)
  Else
    Select Case Err.LastDllError
      Case ERROR_BAD_NETPATH
        Err.Raise 76 ' Pfad nicht gefunden
      Case ERROR_PATH_NOT_FOUND
        Err.Raise 68 ' Gerät nicht verfügbar
      Case ERROR_NOT_READY
        Err.Raise 71 ' Datenträger nicht bereit
      Case Else
        Err.Raise 5  ' Ungültiger Prozeduraufruf/Argument
    End Select
  End If
End Function