Dim MyFile, MyPath, MyName, nMyPath = "c:\*.*" ' 指定路径。 MyName = Dir(MyPath, vbHidden + vbNormal) ' 找寻第一项。 Do While MyName <> "" ' 开始循环。 n = n + 1 MyName = Dir ' 查找下一个。 Loop Debug.Print n
Private Sub Command1_Click() Dim cPath, cName, n cPath = "c:\" cName = Dir(cPath, vbHidden + vbNormal) Do While cName <> "" n = n + 1 cName = Dir Loop MsgBox n End Sub
Set fso = CreateObject("scripting.FileSystemObject") MsgBox fso.GetFolder("c:\").Files.Count
MyName = Dir(MyPath, vbHidden + vbNormal) ' 找寻第一项。
Do While MyName <> "" ' 开始循环。
n = n + 1
MyName = Dir ' 查找下一个。
Loop
Debug.Print n
Dim cPath, cName, n
cPath = "c:\"
cName = Dir(cPath, vbHidden + vbNormal)
Do While cName <> ""
n = n + 1
cName = Dir
Loop
MsgBox n
End Sub
MsgBox fso.GetFolder("c:\").Files.Count