当前位置: 代码迷 >> VBA >> 查找文件解决办法
  详细解决方案

查找文件解决办法

热度:3093   发布时间:2013-02-26 00:00:00.0
查找文件
有一个查找指定文件夹中文件名原程序如下:
Dim s As String
  s = Dir("E:\vbis练习\data\*.shp") '搜索所有文件
  Do While s <> "" '执行搜索
  Print s
  s = Dir()
  Loop
这个程序有两点我不太明白。1、s=Dir()中Dir函数为什么没有参数?2、为什么只列出文件名,而这个文件夹中包含的其他文件夹名称没有列出来?


------解决方案--------------------------------------------------------
列出文件夹:
VB code
Sub test2()MyPath = "d:\"    ' Set the path.MyName = Dir(MyPath, vbDirectory)    ' Retrieve the first entry.Do While MyName <> ""    ' Start the loop.    ' Ignore the current directory and the encompassing directory.    If MyName <> "." And MyName <> ".." Then        ' Use bitwise comparison to make sure MyName is a directory.        If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then            Debug.Print MyName    ' Display entry only if it        End If    ' it represents a directory.    End If    MyName = Dir    ' Get next entry.LoopEnd Sub
  相关解决方案