您的位置:程序门 -> vb -> 基础类



怎么样实现本地文件搜索功能!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎么样实现本地文件搜索功能!
发表于:2007-07-10 14:18:12 楼主
请教各位达人!
输入一个文件名字,就要搜索出在个盘里!
发表于:2007-07-10 14:40:411楼 得分:0
刚才找了一下有一个api可以用的.但是小弟对于这个api还是不太了解~希望有各位达人帮忙一下~~~
public   declare   function   findfirstfile   lib   "kernel32 "   alias   "findfirstfilea "   (byval   lpfilename   as   string,   lpfindfiledata   as   win32_find_data)   as   long

为代码具体怎么样用了
发表于:2007-07-10 14:58:472楼 得分:0
看来你是学生。多下载,多看看代码例子,多动脑。每个入门网站都有此类例子。
发表于:2007-07-10 15:44:073楼 得分:0
哦,,能否提拱个网址啊
发表于:2007-07-10 16:33:494楼 得分:0
www.freevbcode.com
www.planet-source-code.com/vb
www.vbcity.com
....over   thousands   of   vb   source   code   website.
发表于:2007-07-10 16:42:215楼 得分:0
'api函数声明:
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   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   const   ftp_transfer_type_binary   =   &h2
public   const   internet_flag_no_cache_write   =   &h4000000
public   const   format_message_allocate_buffer   =   &h100
public   const   format_message_from_system   =   &h1000
public   const   format_message_ignore_inserts   =   &h200
public   const   invalid_handle_value   =   -1
public   const   file_attribute_directory   =   &h10
public   const   internet_flag_dont_cache   =   &h4000000
public   const   cns_filename_delimeter   =   "/ "
public   const   files_without_dir   =   1
public   const   files_with_dir   =   2
public   const   files_only_dir   =   3
public   const   files_only_dir_including_dot   =   4


public   function   getfilesindir(dirpath   as   string,   strtype   as   string,   withdir   as   integer)   as   string
dim   hf   as   long
dim   str   as   string
dim   strtmp   as   string
dim   filedata   as   win32_find_data
if   strtype   =   " "   then
        strtype   =   "* "
end   if
hf   =   findfirstfile(dirpath   &   "\*. "   &   strtype,   filedata)
if   hf   <>   invalid_handle_value   then
        str   =   stripnulls(filedata.cfilename)
        if   (str   =   ". "   or   str   =   ".. ")   and   withdir   <>   files_only_dir_including_dot   then
                str   =   " "
        end   if
       
        if   withdir   =   files_without_dir   then
                if   str   <>   " "   and   (filedata.dwfileattributes   and   file_attribute_directory)   then
                        str   =   " "
                end   if
                do   while   findnextfile(hf,   filedata)   <>   0
                        strtmp   =   stripnulls(filedata.cfilename)
                        if   strtmp   <>   ". "   and   strtmp   <>   ".. "   and   (filedata.dwfileattributes   and   file_attribute_directory)   =   0   then
                              str   =   str   &   cns_filename_delimeter   &   strtmp
                        end   if
                  loop
        elseif   withdir   =   files_only_dir   then
                if   str   <>   " "   and   (filedata.dwfileattributes   and   file_attribute_directory)   =   0   then
                        str   =   " "
                end   if
                do   while   findnextfile(hf,   filedata)   <>   0
                        strtmp   =   stripnulls(filedata.cfilename)
                        if   strtmp   <>   ". "   and   strtmp   <>   ".. "   and   (filedata.dwfileattributes   and     file_attribute_directory)   then
                              str   =   str   &   cns_filename_delimeter   &   strtmp
                        end   if
                  loop
        elseif   withdir   =   files_with_dir   then   '   including   .   and   ..
                do   while   findnextfile(hf,   filedata)   <>   0
                        strtmp   =   stripnulls(filedata.cfilename)
                              str   =   str   &   cns_filename_delimeter   &   strtmp
                  loop
        elseif   withdir   =   files_only_dir_including_dot   then
                if   str   <>   " "   and   (filedata.dwfileattributes   and   file_attribute_directory)   =   0   then
                        str   =   " "
                end   if
                do   while   findnextfile(hf,   filedata)   <>   0
                        if   (filedata.dwfileattributes   and   file_attribute_directory)   then
                              strtmp   =   stripnulls(filedata.cfilename)
                              str   =   str   &   cns_filename_delimeter   &   strtmp
                        end   if
                loop
        end   if
findclose   hf
end   if
if   mid(str,   1,   1)   =   cns_filename_delimeter   then
        str   =   right(str,   len(str)   -   1)
end   if
getfilesindir   =   str
end   function
发表于:2007-07-10 16:44:556楼 得分:0
1.取得某路径下所有文件列表:
'*************************************************************
'dirpath:读取的路径
'strtype:文件类型   如.dat   .*
'withdir:是否包含目录
'*************************************************************  


快速检索

最新资讯
热门点击