楼上的这种方式是不行的,你怎么能确认文件名中只有1个点呢?我临时给楼主写一个吧,记的引用microsoft scripting runtimePrivate Sub Command1_Click() Dim fso As Scripting.FileSystemObject Dim vFolder As Folder Dim vFile As File Dim attFileName() As StringIf fso.FolderExists("你的文件路径") Then For Each File In vFolder attFileName = Split(vFile.Name, ".") MsgBox attFileName(UBound(attFileName)) '这样才能确保是后缀名称(attFileName(UBound(attFileName))) Next End If End Sub
filebox 控件 在一条一条记录读取```
temp()=split(dir(pathname),".",-1) 文件擴展名=temp(1)
可以用API中的FindFirstFile,FindNextFile,FindClose函数 Option ExplicitPublic Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As LongPublic Const MAX_PATH = 260 Public Const INVALID_HANDLE_VALUE = -1Public Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End TypePublic Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End TypePublic Function GetFiles(strParentPath As String) As String Dim File As String Dim FindHandle As Long Dim WFD As WIN32_FIND_DATA Dim FileName As String strParentPath = NormalizePath(strParentPath)
Do FileName = Mid(WFD.cFileName, 1, InStr(1, WFD.cFileName, vbNullChar) - 1) If (FileName <> "." And FileName <> "..") Then
If (WFD.dwFileAttributes <> vbDirectory) Then
If InStr(1, Right(FileName, 5), ".") > 0 Then File = strParentPath & FileName MsgBox File End If
End If
Loop While FindNextFile(FindHandle, WFD)
Call FindClose(FindHandle)
End If
GetFiles = File
End Function Public Function NormalizePath(sPath As String) As String If Right$(sPath, 1) <> "\" Then NormalizePath = sPath & "\" Else NormalizePath = sPath End If
循环找出文件名,再mid(filename,instr(1,filename,".")+1,3)
Dim fso As Scripting.FileSystemObject
Dim vFolder As Folder
Dim vFile As File
Dim attFileName() As StringIf fso.FolderExists("你的文件路径") Then
For Each File In vFolder
attFileName = Split(vFile.Name, ".")
MsgBox attFileName(UBound(attFileName))
'这样才能确保是后缀名称(attFileName(UBound(attFileName)))
Next
End If
End Sub
文件擴展名=temp(1)
Option ExplicitPublic Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As LongPublic Const MAX_PATH = 260
Public Const INVALID_HANDLE_VALUE = -1Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End TypePublic Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End TypePublic Function GetFiles(strParentPath As String) As String Dim File As String
Dim FindHandle As Long
Dim WFD As WIN32_FIND_DATA
Dim FileName As String strParentPath = NormalizePath(strParentPath)
FindHandle = FindFirstFile(strParentPath & "*.*", WFD)
If (FindHandle <> INVALID_HANDLE_VALUE) Then
Do
FileName = Mid(WFD.cFileName, 1, InStr(1, WFD.cFileName, vbNullChar) - 1) If (FileName <> "." And FileName <> "..") Then
If (WFD.dwFileAttributes <> vbDirectory) Then
If InStr(1, Right(FileName, 5), ".") > 0 Then File = strParentPath & FileName
MsgBox File
End If
End If
Loop While FindNextFile(FindHandle, WFD)
Call FindClose(FindHandle)
End If
GetFiles = File
End Function
Public Function NormalizePath(sPath As String) As String If Right$(sPath, 1) <> "\" Then
NormalizePath = sPath & "\"
Else
NormalizePath = sPath
End If
End Function
'有意者可加我的QQ:342666594