VB 版 (精华区)
发信人: zxfsnow (希望的春天), 信区: VB
标 题: 文件名解析程序(smth - erain)
发信站: 哈工大紫丁香 (2000年06月05日12:50:27 星期一), 转信
发信人: gnim (阿笨-2代), 信区: VB
标 题: 文件名解析程序(smth - erain)
发信站: 虎踞龙蟠 (Wed Apr 26 19:51:24 2000), 转信
发信人: erain (红花会主), 信区: VisualBasic
标 题: 文件名解析程序
发信站: BBS 水木清华站 (Tue Apr 25 18:01:22 2000)
这里给大家提供一个文件名解析的程序,非常的好用,尤其是在使用了
通用对话框获得一个文件的完整路径之后,利用这个程序你可以解析
出关于一个文件所有有用的东东,
例如后缀啦
路径啦(不含文件名)
带后缀的文件名
文件是不是可以使用啦,等等
我一直在用的,非常方便,
使用前,要先定义自定义类型
Public Type PathInfo
FileNamewExt As String
FileNamewoExt As String
FileExt As String
FilePath As String
FileIsValid As Boolean
End Type
Public Sub ExtractInfo(Source As String, ReturnInfo As PathInfo)
Dim intCurrentPos As Integer, intFileNamePos As Integer
Dim intFileExtPos As Integer
'clear UDT passed in if there is any existing data
ReturnInfo.FileExt = ""
ReturnInfo.FileIsValid = False
ReturnInfo.FileNamewExt = ""
ReturnInfo.FileNamewoExt = ""
ReturnInfo.FilePath = ""
If Source <> "" Then
'get file name by finding the last slash in the string
Do
intCurrentPos = InStr(intCurrentPos + 1, Source, "\", vbTextComp
are)
If intCurrentPos <> 0 Then
intFileNamePos = intCurrentPos
Else
intFileNamePos = intFileNamePos + 1
Exit Do
End If
Loop
'get file extension position if any
intFileExtPos = InStr(intFileNamePos, Source, ".", vbTextCompare) +
1
If intFileExtPos = 1 Then
Exit Sub
End If
'put data in UDT passed in
If intFileNamePos <> 1 Then
ReturnInfo.FileNamewExt = Mid(Source, intFileNamePos, Len(Source
) - intFileNamePos + 1)
ReturnInfo.FilePath = Mid(Source, 1, intFileNamePos - 2)
End If
If intFileNamePos <> 1 And intFileExtPos <> 1 Then
ReturnInfo.FileNamewoExt = Mid(Source, intFileNamePos, intFileEx
tPos - intFileNamePos - 1)
ReturnInfo.FileExt = Mid(Source, intFileExtPos, Len(Source) - in
tFileExtPos + 1)
End If
If Dir(Source, vbArchive + vbHidden + vbNormal + vbReadOnly + vbSyst
em) <> "" Then
ReturnInfo.FileIsValid = True
Else
ReturnInfo.FileIsValid = False
End If
End If
End Sub
--
巧者劳而智者忧,无能者无所求,饱食而遨游,泛若不系之舟。
请稍候,正在戒网中......
__________________________________________________________________
|泉水叮咚 20% |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
--
以科计为本,以产业报国!
超越自我,飞跃无限!
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.235.249]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.207毫秒