Function SearchFiles(Path As String, FileType As String)
Dim Files() As String '文件路径
Dim Folder() As String '文件夹路径
Dim a, b, c As Long
Dim sPath As String
'sPath = Dir(Path & FileType) '查找第一个文件
Do While Len(sPath) '循环到没有文件为止
a = a + 1
ReDim Preserve Files(1 To a)
Files(a) = Path & sPath '将文件目录和文件名组合,并存放到数组中
List1.AddItem Files(a) '加入list控件中
sPath = Dir '查找下一个文件
DoEvents '让出控制权
Loop
sPath = Dir(Path & "\", vbDirectory) '查找第一个文件夹
Do While Len(sPath) '循环到没有文件夹为止
If Left(sPath, 1) <> "." Then '为了防止重复查找
If GetAttr(Path & "\" & sPath) And vbDirectory Then '如果是文件夹则。。。。。。
b = b + 1
ReDim Preserve Folder(1 To b)
Folder(b) = Path & sPath & "\" '将目录和文件夹名称组合形成新的目录,并存放到数组中
End If
End If
sPath = Dir '查找下一个文件夹
DoEvents '让出控制权
Loop
For c = 1 To b '使用递归方法,遍历所有目录
SearchFiles Folder(c), FileType
Next
End Function
Private Sub Command1_Click() '调用
SearchFiles "e:\", "*.*"
End Sub
VB 实时错误52 错误的文件名或号码
答案:2 悬赏:30 手机版
解决时间 2021-03-19 23:13
- 提问者网友:不爱我么
- 2021-03-19 14:24
最佳答案
- 五星知识达人网友:时间的尘埃
- 2019-10-02 00:06
'sPath = Dir(Path & FileType) '查找第一个文件
这句前面的单引号去掉
SearchFiles "e:\", "*.*" 这句改为
SearchFiles "e:\", "1.txt"
这个代码本身是查找“某个目录下面是不是有某个文件”的
不是查找所有文件的
这句前面的单引号去掉
SearchFiles "e:\", "*.*" 这句改为
SearchFiles "e:\", "1.txt"
这个代码本身是查找“某个目录下面是不是有某个文件”的
不是查找所有文件的
全部回答
- 1楼网友:渊鱼
- 2020-09-11 21:35
t = month(date)
d = day(date)
open "jieri.txt" for input as #2
dim jmonth$, jday$, name$
do while not eof(2)
input #2, jmonth, jday, name 'input #2, 这里错误 应该是line input#2,一个变量,用于装载此行的内容!
if t <> val(jmonth) or d <> val(jday) then l = 0
loop
close #2
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯