以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 请教查找文件 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=129658) |
-- 作者:hbhb -- 发布时间:2019/1/3 11:51:00 -- 请教查找文件 大师:请问如何最快的速度,查询出*.mdb文件? |
-- 作者:有点甜 -- 发布时间:2019/1/3 11:56:00 -- 参考
http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=121108&skin=0
|
-- 作者:hbhb -- 发布时间:2019/1/3 19:10:00 -- 谢谢!直接返回一个集合,怎么该全局代码? |
-- 作者:hbhb -- 发布时间:2019/1/3 19:11:00 -- 谢谢!直接返回一个集合,怎么改全局代码? |
-- 作者:有点甜 -- 发布时间:2019/1/3 20:05:00 -- 以下是引用hbhb在2019/1/3 19:11:00的发言:
谢谢!直接返回一个集合,怎么改全局代码?
认认真真看懂2楼,测试对应的代码。 |
-- 作者:hbhb -- 发布时间:2019/1/4 11:59:00 -- 我要增加一个文件后缀名的参数,返回一个次文件后缀名的集合,下面的代码为何不对?不同的后缀名参数,返回的集合会累计元素?,如何更改? <DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _ Public Function FindFirstFile(ByVal pFileName As String, ByRef pFindFileData As WIN32_FIND_DATA) As IntPtr End Function <DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _ Public Function FindNextFile(ByVal hndFindFile As IntPtr, ByRef lpFindFileData As WIN32_FIND_DATA) As Boolean End Function <DllImport("kernel32.dll", SetLastError:=True)> _ Public Function FindClose(ByVal hndFindFile As IntPtr) As Boolean End Function <Serializable, StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto), BestFitMapping(False)> _ Public Structure WIN32_FIND_DATA Public dwFileAttributes As IO.FileAttributes Public ftCreationTime_dwLowDateTime As UInteger Public ftCreationTime_dwHighDateTime As UInteger Public ftLastAccessTime_dwLowDateTime As UInteger Public ftLastAccessTime_dwHighDateTime As UInteger Public ftLastWriteTime_dwLowDateTime As UInteger Public ftLastWriteTime_dwHighDateTime As UInteger Public nFileSizeHigh As UInteger Public nFileSizeLow As UInteger Public dwReserved0 As Integer Public dwReserved1 As Integer <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _ Public cFileName As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)> _ Public cAlternateFileName As String End Structure Dim a As new List(of String) Public Function EnumerateFiles(ByVal path As String, ByVal Optional searchPattern As String = "*.*",ByVal Optional zfc As String = ".*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories) Dim hFind As IntPtr = -1 Dim FindFileData As WIN32_FIND_DATA = Nothing hFind = FindFirstFile(IO.Path.Combine(path, searchPattern), FindFileData) If hFind <> -1 Then Do If FindFileData.cFileName.Equals(".") OrElse FindFileData.cFileName.Equals("..") Then Continue Do If searchOption = io.SearchOption.AllDirectories AndAlso ((FindFileData.dwFileAttributes And io.FileAttributes.Directory) = io.FileAttributes.Directory) Then \'output.show(io.Path.Combine(path, FindFileData.cFileName)) EnumerateFiles(io.Path.Combine(path, FindFileData.cFileName),"*.*",zfc) Else \'output.show(io.Path.Combine(path, FindFileData.cFileName)) Dim b As String = io.Path.Combine(path, FindFileData.cFileName) If b.Contains(zfc) Then a.Add(io.Path.Combine(path, FindFileData.cFileName)) End If End If Loop While FindNextFile(hFind, FindFileData) FindClose(hFind) End If Return a End Function |
-- 作者:有点甜 -- 发布时间:2019/1/4 12:04:00 -- 你调用的时候,可以设置后缀名的啊
Public Function EnumerateFiles(ByVal path As String, ByVal Optional searchPattern As String = "*.*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories) |
-- 作者:hbhb -- 发布时间:2019/1/4 13:04:00 -- 如果这样不显示前面路径下的所有的目录及子目录的。我测试过了。另外我要返回一个集合? |
-- 作者:有点甜 -- 发布时间:2019/1/4 15:50:00 -- 调用代码
_list.clear
全局代码
Public _list As new List(of String) <DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _ <Serializable, StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto), BestFitMapping(False)> _ Public Function EnumerateFiles(ByVal path As String, ByVal Optional searchPattern As String = "*.*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories) hFind = FindFirstFile(IO.Path.Combine(path, searchPattern), FindFileData) End Function |
-- 作者:hbhb -- 发布时间:2019/1/4 19:30:00 -- 谢谢! 搜索一硬盘时间太长,
如果要停止搜索,按钮中的代码怎么写? |