level 6
用API搜索文件夹,是图片后缀的就添加进list。
或者直接用FILELIST,筛选,然后导入list
2009年12月15日 05点12分
5
level 13
'枚举指定文件夹下之图片文件
'添加 Command1 List1
Option Explicit '强制宣告定义变量
'定义变量
Dim aa$, SchPath$, Fname$, ExtNm$, PicList$, jj&, Tpic&, FilePath$()
Dim SpShell, SpFolder, SpFolderItem, SsfDrives$
Private Sub Form_Load()
'将窗体居中显示 (屏幕宽度减去窗体的宽度)除以2 , (屏幕高度减去窗体的高度)除以2
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
End Sub
Private Sub Command1_Click()
Tpic = 0: Fname = ""
PicList = "BMP,GIF,JPG"
Call SelDir
Fname = Dir(SchPath & "*.*")
If Fname = "" Then MsgBox "本文件夹中没有任何文件": Exit Sub
List1.Clear
Do While Len(Fname) > 0
ExtNm = UCase(GetExtNm(Fname))
If ExtNm<>"" And InStr(PicList, ExtNm) > 0 Then
ReDim Preserve FilePath(Tpic)
FilePath(Tpic) = SchPath & Fname
List1.AddItem SchPath & Fname
Tpic = Tpic + 1
End If
Fname = Dir
Loop
aa = IIf(Tpic > 0, "共有:" & Str(Tpic) & " 个图片文件", "没有选择图片文件")
MsgBox aa
End Sub
Sub SelDir()
On Error GoTo errhandle '有错误或选择取消返回32755的错误代号,执行错误处理副程序
Set SpShell = CreateObject("Shell.Application") '创建对像
Set SpFolder = SpShell.BrowseForFolder(0, "选择目录:", 0, SsfDrives) '定义spFolder=定义对像展开目录
Set SpFolderItem = SpFolder.Self '定义spFolderItem
SchPath = SpFolderItem.Path 'spPath=选中的spFolderItem文件夹路径
If Right(SchPath, 1) <> "\" Then SchPath = SchPath & "\"
errhandle: '错误处理副程序
If Err > 0 Then Exit Sub '有错误即退出这个sub
End Sub
Public Function GetExtNm(Fnm$) As String
jj = InStrRev(Fnm, ".")
GetExtNm = ""
If jj > 0 Then GetExtNm = Mid(Fnm, jj + 1)
End Function
2009年12月15日 12点12分
8