Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共9 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:调用Windows API

1楼
1498351234 发表于:2018/6/29 11:34:00
老师好!我要处理数以万计的文件,需要用到windows 文件搜索的  API,也知道用FindFirstFile和FindNextFile函数,但不知道如何引用,要求在全局代码中引用,给个使用范例吧
[此贴子已经被作者于2018/6/29 11:34:57编辑过]
2楼
有点甜 发表于:2018/6/29 11:37:00

1、参考

 

http://www.foxtable.com/webhelp/scr/0331.htm

 

2、参考

 

http://www.foxtable.com/webhelp/scr/1937.htm

 

3楼
1498351234 发表于:2018/6/29 11:45:00
参考1得自己写,用到递归函数。参考2,看不懂啊,就是要个例子,如何调用这个函数,用的是哪个dll文件。
4楼
有点甜 发表于:2018/6/29 12:14:00

递归参考

 

 下载信息  [文件大小:292.0 KB  下载次数:5]
图片点击可在新窗口打开查看点击浏览该文件:文件递归.table

5楼
有点甜 发表于:2018/6/29 13:38: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

Public Function EnumerateFiles(ByVal path As String, ByVal Optional searchPattern 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))
        Else
            output.show(io.Path.Combine(path, FindFileData.cFileName))
        End If

    Loop While FindNextFile(hFind, FindFileData)
    FindClose(hFind)
   
End If

End Function

 

 

调用代码

 

EnumerateFiles("d:\")

6楼
1498351234 发表于:2018/6/29 15:22:00
谢谢老师!太好了!
7楼
fubblyc 发表于:2019/8/13 9:39:00
文件夹mark
8楼
zhy400137 发表于:2019/9/18 22:16:00
文件搜索 mark
9楼
keli0917 发表于:2024/11/23 10:49:00
图片点击可在新窗口打开查看文件查找。MARK
共9 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 2 queries.