说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB取得文件的扩展名

HTML文档下载 WORD文档下载 PDF文档下载
VB取得文件的扩展名
Function GetExtension(Filename As String)
Dim PthPos, ExtPos As Integer

For i = Len(Filename) To 1 Step -1 ' Go from the Length of the filename, to the first character by 1.
If Mid(Filename, i, 1) = "." Then ' If the current position is '.' then...
ExtPos = i ' ...Change the ExtPos to the number.
For j = Len(Filename) To 1 Step -1 ' Do the Same...
If Mid(Filename, j, 1) = "\" Then ' ...but for '\'.
PthPos = j ' Change the PthPos to the number.
Exit For ' Since we found it, don't search any more.
End If
Next j
Exit For ' Since we found it, don't search any more.
End If
Next i

If PthPos > ExtPos Then
Exit Function ' No extension.
Else
If ExtPos = 0 Then Exit Function ' If there is not extension, then exit sub.
GetExtension = Mid(Filename, ExtPos + 1, Len(Filename) - ExtPos) 'Messagebox the Extension
End If

End Function
使用:
FileExt = GetExtension("c:\windows\vb\vb.exe")

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘