如何知道指定文件夹中(无子文件夹)ico文件的个数?
如何知道各个文件的名字?然后我要循环放入imagelist中For I = 1 To 数量
ImageList1.ListImages.Add I, 文件名,
LoadPicture( App.Path & "\ICO\" & "文件名" & ".ico")
Next I
如何知道各个文件的名字?然后我要循环放入imagelist中For I = 1 To 数量
ImageList1.ListImages.Add I, 文件名,
LoadPicture( App.Path & "\ICO\" & "文件名" & ".ico")
Next I
Function GetFiles(filespec As String, Optional Attributes As VbFileAttribute) As String()
Dim result() As String
Dim filename As String, count As Long, path2 As String
Const ALLOC_Chunk = 1
ReDim result(ALLOC_Chunk) As String
filename = Dir$(filespec, Attributes)
Do While Len(filename)
count = count + 1
If count > UBound(result) Then
ReDim Preserve result(0 To count + ALLOC_Chunk) As String
End If
result(count) = filename
filename = Dir$
Loop
ReDim Preserve result(0 To count) As String
GetFiles = result
End Function这个函数中的count就是文件数量,result数组里面保存的就是文件名
Dim n As Integer, dirlevel As Integer, fname As String, dirlist() As String, num As Long
num = 0
mydir = IIf(Right(mydir, 1) = "\", mydir, mydir & "\")
fname = Dir(mydir)
Do While fname <> ""
If LCase(Trim(Mid(fname, Len(fname) - 2))) = "ico" Then
Debug.Print mydir & fname
'就在这里装入图片,mydir & fname就是完整的路径名
End If
num = num + 1
fname = Dir
DoEvents
Loop
fname = LCase(Dir(mydir, vbDirectory))
Do While fname <> ""
If fname <> "." And fname <> ".." Then
If GetAttr(mydir & fname) And vbDirectory Then
dirlevel = dirlevel + 1
ReDim Preserve dirlist(dirlevel)
dirlist(dirlevel) = mydir & fname
End If
End If
fname = Dir
DoEvents
Loop
For n = 1 To dirlevel
Listfiles dirlist(n) & "\"
Next
End SubPrivate Sub Command1_Click()
Listfiles "d:\"
End Sub
上面的参数filespec 指的是目录,比如:path & "*.*",如果要取得特殊文件名可以使用:
GetFiles(path & "*." & "exe"),取得扩展名为exe的文件名字以及数量