Lly's Blog

 VB遍历文件夹中的图片

Lly, 发表于:2018-05-10 20:50:40, 分类:资源共享 浏览( ) 评论( )  收藏这篇日志

 '一个窗体,一个list,一启动就会自动把给定的目录里所有的jpg文件读出,并添加到list中。by fallx
Private Sub Form_Load()
On Error GoTo errEvent
Dim strFileName() As String
Dim strPath As String
Dim intCount, i As Long
Dim strFile As String
intCount = 0
strPath = "D:\相片\" & "*.jpg" '这个目录可以改为用 打开文件夹给出,*.jpg限定文件类型
strFile = Dir(strPath)
While strFile <> "" '搜索给定目录下的所有该类型文件
DoEvents
intCount = intCount + 1
ReDim Preserve strFileName(intCount) As String '重定义数组
strFileName(intCount - 1) = strFile '把文件名存到数组中
strFile = Dir '再取下一个
Wend
For i = 0 To intCount - 1
List1.AddItem strFileName(i) & ".jpg" '将文件名插入listbox的里面
Next i
Exit Sub
errEvent:
MsgBox "非常抱歉,出错,部分或全部图片无法读取!"
End Sub

 暂无标签
正在读取日志的评论数据,请稍后……
正在加载日志评论签写框,请稍后……
 成员登录通道
正在载入成员登录通道...
 BLOG 日历助手
正在载入日历助手...
 BLOG 统计信息
正在载入统计信息...
 BLOG 日志归档
 BLOG 推荐日志
  • 暂时没有推荐日志
 BLOG 最新评论
{$SideComment}
 BLOG 最新留言
{$SideGB}
 BLOG 站内搜索

Tags Cloud: