首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 冲浪宝典-> 局域网
VB中枚举指定目录下所有文件的方法-.NET教程,评论及其它
作者:网友供稿 点击:195
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
有同学问我这个问题,我就把代码贴在这里吧。

module1.bas文件:
public const max_path = 260

public const file_attribute_archive = &h20
public const file_attribute_hidden = &h2
public const invalid_handle_value = -1


public type filetime
dwlowdatetime as long
dwhighdatetime as long
end type

public 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 type

public 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 long


public function getfullallfilefilter(directory as string) as string
getfullallfilefilter = directory + "\*.*"
end function


frmmain.frm文件:
version 5.00
begin vb.form frmmain
borderstyle = 3 fixed dialog
caption = "enum files demo"
clientheight = 4770
clientleft = 3210
clienttop = 1905
clientwidth = 4920
beginproperty font
name = "宋体"
size = 9
charset = 134
weight = 400
underline = 0 false
italic = 0 false
strikethrough = 0 false
endproperty
linktopic = "form1"
maxbutton = 0 false
minbutton = 0 false
scaleheight = 4770
scalewidth = 4920
showintaskbar = 0 false
begin vb.commandbutton cmdlist
caption = "&enumfiles"
height = 375
left = 3600
tabindex = 3
top = 1800
width = 1215
end
begin vb.dirlistbox dir
height = 1140
left = 0
tabindex = 2
top = 480
width = 4935
end
begin vb.drivelistbox drive
height = 300
left = 0
tabindex = 1
top = 120
width = 4935
end
begin vb.listbox lstfilenames
height = 2400
itemdata = "frmmain.frx":0000
left = 0
list = "frmmain.frx":0002
tabindex = 0
top = 2280
width = 4935
end
begin vb.label label1
caption = "click enumfiles button to list all files in specified directory."
height = 495
left = 120
tabindex = 4
top = 1680
width = 3375
end
end
attribute vb_name = "frmmain"
attribute vb_globalnamespace = false
attribute vb_creatable = false
attribute vb_predeclaredid = true
attribute vb_exposed = false
option explicit

private sub cmdlist_click()
dim lpfiledata as win32_find_data 保存找到的文件的信息
dim hfindfile as long 文件查找句柄
dim findpattern as string 查询的文件模式
dim tmp as boolean

获得模式
findpattern = getfullallfilefilter(dir.path)

查找第一个文件
hfindfile = findfirstfile(findpattern, lpfiledata)

如果没有找到
if hfindfile = invalid_handle_value then
exit sub
end if

清除列表
lstfilenames.clear

设置临时变量
tmp = true

do while tmp
如果找到的是文件而不是目录
(如果连隐藏文件都要一并找出,该条件改为:
if lpfiledata.dwfileattributes and (file_attribute_archive or file_attribute_hidden) then ...)
if lpfiledata.dwfileattributes and file_attribute_archive then
将文件名添加到列表中
lstfilenames.additem lpfiledata.cfilename
end if
查找下一个文件
tmp = findnextfile(hfindfile, lpfiledata)
loop
全部查询完毕,关闭句柄
findclose hfindfile
end sub

private sub drive_change()
dir.path = drive.drive
end sub

private sub form_load()
dir.path = drive.drive
end sub



文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·Java串行端口技术协议-JSP教程,Java技巧及代码
·VB6中水晶报表(Crystal Report 4.6)的使用经验-.NET教程,报表/图形/Office
·一种全新的软件界面设计方法(摘)-.NET教程,Asp.Net开发
·RSA加密算法在VB中的实现-.NET教程,VB.Net语言
·ubb代码转化html代码-ASP教程,脚本编码
·用C#创建可拖动窗体-.NET教程,C#语言
·ASP技术访问WEB数据库-ASP教程,数据库相关
·浅谈基站蓄电池的维护与保养
·VB中枚举指定目录下所有文件的方法-.NET教程,评论及其它
·ADO.NET 2.0 Dataset和Datatable 新功能新特性-.NET教程,Asp.Net开发
最新文章
·解决局域网遭遇盗用mac地址上网的问题_局域网教程
·photoshop将照片处理为艺术插画特效_photoshop教程
·狂人!用日ip不到500的站一年赚了10万元_网赚技巧
·李治国:急躁公司做不了分类信息_站长访谈
·李彦宏教你创业实用的七大招_站长心得
·新站如何被百度快速的收录_站长心得
·影响搜索排名的77种因素_站长心得
·网站站长把你懂的东西卖给不懂的人,才能赚钱_站长心得
·个人站点提高访问量谋略1_站长心得
·做adsense的一些经验_google推广
相关主题
西部数码虚拟主机

友情链接
CNNIC 西部数码
万网 自助建站
虚拟主机 asp空间
域名注册 域名
域名申请 主页空间
论坛空间 网站空间
国际域名 虚拟空间
空间租用 DDOS防火墙
成都主机托管 四川主机托管
主机租用 服务器租用
网站目录 自助建站
虚拟主机 网址大全
软件下载
自助链接
虚拟主机资讯 特价虚拟主机
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
发表评论 打印  刷新     关闭