![]() |
Tipp 0148
|
Dateinamen analysieren
|
 |
|
Autor/Einsender: Datum: |
|
Peter Wagenbauer 20.02.2005 (Update) |
|
Entwicklungsumgebung: |
|
VB 6 |
|
|
Mit folgenden Funktionen lassen sich alle wichtigen Komponenten eines Dateinamens, wie
Laufwerk, Pfad, Kennung usw., ermitteln.
|
|
Code im Codebereich des Moduls |
|
|
Option Explicit
Public Function gDrive(ByVal sFileName As String) As String
'Argument: Dateiname inkl. Pfad
'Rückgabe: Laufwerk
Dim nPos As Long
On Error Resume Next
If Left$(sFileName, 2) = "\\" Then
nPos = InStr(3, sFileName, "\")
gDrive = Left$(sFileName, nPos - 1)
Else
nPos = InStr(sFileName, ":")
gDrive = Left$(sFileName, nPos)
End If
On Error GoTo 0
End Function
Public Function gPath(ByVal sFileName As String) As String
'Argument: Dateiname inkl. Pfad
'Rückgabe: Pfad ohne Dateinamen
Dim nPos As Long
nPos = InStrRev(sFileName, "\")
If nPos <> 0 Then
gPath = Left$(sFileName, nPos)
End If
End Function
Public Function gFileTitle(ByVal sFileName As String) As String
'Argument: Dateiname inkl. Pfad
'Rückgabe: Dateiname ohne Pfad
Dim nPos As Long
nPos = InStrRev(sFileName, "\")
If nPos <> 0 Then
gFileTitle = Mid$(sFileName, nPos + 1)
Else
gFileTitle = sFileName
End If
End Function
Public Function gFileWithoutExt(ByVal sFileTitle As String) _
As String
'Argument: Dateiname ohne Pfad
'Rückgabe: Dateiname ohne Kennung/Endung
Dim nPos As Long
nPos = InStrRev(sFileTitle, ".")
If nPos <> 0 Then
gFileWithoutExt = Left$(sFileTitle, nPos - 1)
Else
gFileWithoutExt = sFileTitle
End If
End Function
Public Function gFileExtension(ByVal sFileTitle As String) _
As String
'Argument: Dateiname ohne Pfad
'Rückgabe: Kennung/Endung
Dim nPos As Long
nPos = InStrRev(sFileTitle, ".")
If nPos <> 0 Then
gFileExtension = Mid(sFileTitle, nPos + 1)
End If
End Function
|
|
|
|
|
Dim strFileName As String
Dim strRetVal As String
strFileName = "c:\temp\beispiel.vbp"
strRetVal = gDrive(strFileName)
MsgBox "Laufwerk: " & strRetVal
strRetVal = gPath(strFileName)
MsgBox "Pfad ohne Dateiname: " & strRetVal
strRetVal = gFileTitle(strFileName)
MsgBox "Dateiname ohne Pfad: " & strRetVal
strRetVal = gFileWithoutExt(gFileTitle(strFileName))
MsgBox "Dateiname ohne Kennung/Endung: " & strRetVal
strRetVal = gFileExtension(gFileTitle(strFileName))
MsgBox "Kennung/Endung: " & strRetVal
|
|
|
|
|
|
Die im Download befindliche *.bas-Datei kann für die Verwendung in einem
VBA 6-Projekt (ab Office 2000) im VB-Editor des entsprechenden Programms
importiert werden. Ein Import der im Download enthaltenen *.frm-Datei ist
nicht möglich.
|
|
Windows-Version |
95 |
 |
|
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
VB-Version |
VBA 5 |
 |
|
VBA 6 |
 |
|
VB 4/16 |
 |
|
VB 4/32 |
 |
|
VB 5 |
 |
|
VB 6 |
 |
|
|
|
Download (4 kB)
|
Downloads bisher: [ 2028 ]
|
|
|