遍历给定目录下的所有文件 c

来源:百度知道 编辑:UC知道 时间:2024/05/26 03:32:39
只是文件就可以,而且路径已给定,就像cmd中显示c盘中目录那样就行

Dim MyFile As String,sPath As String
sPath="c:\windows"
MyFile = Dir(sPath, vbDirectory Or vbHidden Or vbSystem Or vbReadOnly)
Do While MyFile <> ""
If (GetAttr(sPath & MyFile) And vbDirectory) = vbDirectory Then
List1.AddItem MyFile
Else
List2.AddItem MyFile
End If
MyFile = Dir
Loop
Debug.Print "共计:" & List1.ListCount & "个目录 " & List2.ListCount & "个文件"

Private Sub Command1_Click()
MyName = Dir("z:\")
Do While MyName <> ""
Debug.Print MyName
MyName = Dir
Loop
End Sub

用File1控件