如何实现遍历文件夹中的所有文件
时 间:2008-05-19 08:16:55
作 者:UMVSOFT整理 ID:16 城市:江阴
摘 要:如何实现遍历文件夹中的所有文件
正 文:
如何实现遍历文件夹中的所有文件 办法如下: 把下面放到模块中 Option Explicit 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 Const MAX_PATH = 260 Public Const FILE_ATTRIBUTE_ARCHIVE = &H20 Public Const FILE_ATTRIBUTE_COMPRESSED = &H800 Public Const FILE_ATTRIBUTE_DIRECTORY = &H10 Public Const FILE_ATTRIBUTE_HIDDEN = &H2 Public Const FILE_ATTRIBUTE_NORMAL = &H80 Public Const FILE_ATTRIBUTE_READONLY = &H1 Public Const FILE_ATTRIBUTE_SYSTEM = &H4 Public Const FILE_ATTRIBUTE_TEMPORARY = &H100 '自定义数据类型FILETIME和WIN32_FIND_DATA的定义 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 ---------------------- '-------------------------------------------------------------------------------- ' 把当前文件夹路径下的所有文件入到listview中 '-------------------------------------------------------------------------------- Private Sub finfiles(tCurrentdir As String) Dim itmX As ListItem Dim tFindData As WIN32_FIND_DATA Dim strFileName As String Dim lHandle As Long Dim CountFolder As Integer Dim CountFiles As Integer CountFolder = 0 CountFiles = 0 ListView1.ListItems.Clear lHandle = FindFirstFile(tCurrentdir & "*.*", tFindData) If lHandle = 0 Then Set itmX = ListView1.ListItems.Add(, , strFileName & "找不到文件") Exit Sub End If strFileName = fDelInvaildChr(tFindData.cFileName) Do While True tFindData.cFileName = "" If FindNextFile(lHandle, tFindData) = 0 Then FindClose (lHandle) Exit Do Else strFileName = fDelInvaildChr(tFindData.cFileName) If tFindData.dwFileAttributes = &H10 Then If strFileName <> "." And strFileName <> "." Then Set itmX = ListView1.ListItems.Add(, , strFileName) itmX.SmallIcon = 1 CountFolder = CountFolder + 1 End If Else Debug.Print InStr(LCase(Right(strFileName, 3)), ExtendFileName) If InStr(ExtendFileName, LCase(Right(strFileName, 3))) > 0 Then Set itmX = ListView1.ListItems.Add(, , strFileName) itmX.SubItems(1) = CStr(FileLen(tCurrentdir & "" & strFileName)) itmX.SmallIcon = 2 itmX.SubItems(2) = FileDateTime(tCurrentdir & "" & strFileName) CountFiles = CountFiles + 1 End If End If End If Loop ListView1.Sorted = True ListView1.SortKey = 1 StatusBar1.Panels(2).Text = CurrentDir StatusBar1.Panels(3).Text = "文件夹:" & CountFolder & " 文件:" & CountFiles End Sub
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)
- Access快速开发平台--让有权...(11.04)
- Access快速开发平台--审批选...(11.01)
- ACCESS两张表先各自排序,然后...(10.31)
- Access对子窗体数据进行批量+...(10.30)
- SqlServer中如何用SQL命...(10.29)
- Access报表中的分组功能用代码...(10.28)
- 用Access计算库存结余的一个方...(10.26)
- 最精简的组合框行来源数据快速输入(...(10.25)