手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

用API函数遍历指定路径的文件

来源:互联网 作者:西部数码 时间:2008-04-09
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

  Loop
  Cont = FindClose(hSearch)
 End If
 ' 遍历目录并累计文件总数
 hSearch = FindFirstFile(path & SearchStr, WFD)
 Cont = True
 If hSearch <> INVALID_HANDLE_VALUE Then
  While Cont
   FileName = StripNulls(WFD.cFileName)
   If (FileName <> ".") And (FileName <> "..") Then
    FindFilesAPI = FindFilesAPI (WFD.nFileSizeHigh * MAXDWORD) WFD.nFileSizeLow
    FileCount = FileCount 1
    List1.AddItem path & FileName
   End If
   Cont = FindNextFile(hSearch, WFD) ' 获取下一个文件
  Wend
  Cont = FindClose(hSearch)
 End If
 '如果子目录存在则遍历之
 If nDir > 0 Then
  For i = 0 To nDir - 1
   FindFilesAPI = FindFilesAPI FindFilesAPI(path & dirNames(i) & "\", _
SearchStr, FileCount, DirCount)
  Next i
 End If
End Function


'查找按钮代码
Sub Command1_Click()
 Dim SearchPath As String, FindStr As String
 Dim FileSize As Long
 Dim NumFiles As Integer, NumDirs As Integer
 Dim iNull As Integer, lpIDList As Long, lResult As Long
 Dim sPath As String, udtBI As BrowseInfo
 With udtBI
  '设置浏览窗口
  .hWndOwner = Me.hWnd
  '返回选中的目录
  .ulFlags = BIF_RETURNONLYFSDIRS
 End With


 '调出浏览窗口
 lpIDList = SHBrowseForFolder(udtBI)
 If lpIDList Then
  sPath = String$(MAX_PATH, 0)
  '获取路径
  SHGetPathFromIDList lpIDList, sPath
  '释放内存
  CoTaskMemFree lpIDList
  iNull = InStr(sPath, vbNullChar)
  If iNull Then
   sPath = Left$(sPath, iNull - 1)
  End If
 End If
 Screen.MousePointer = vbHourglass
 List1.Clear
 SearchPath = sPath '选中的目录为搜索的起始路径
 FindStr = "*.*" '搜索所有类型的文件(此处可另作定义)
 FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
 Text1.Text = "查找到的文件数:" & NumFiles & vbCrLf & "查找的目录数:" & _
NumDirs 1 & vbCrLf & "文件大小总共为:" & vbCrLf & _
Format(FileSize, "#,###,###,##0") & "字节"
 Screen.MousePointer = vbDefault
End Sub

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!