dir函数读取相应路径下的文件名或文件夹名
'1 遍历文件夹
mypath1 = ThisWorkbook.path & "\"
folename = Dir(mypath1, vbDirectory) '这里主要是Dir的第二个参数的变化
Do
If Not folename Like "*.*" Then 'if判断语句主要是去掉(当前目录和上一级目录的标识符“.”“..”,去掉点)
str1 = folename
k = k + 1
ReDim Preserve arr1(1 To k)
arr1(k) = folename '将文件夹名存入数组
End If
folename = Dir
Loop Until folename = ""
'2 遍历文件
For Each a In arr1
mypath2 = mypath1 & a & "\"
filename = Dir(mypath2)
Do
str2 = a & "\" & filename
l = l + 1
ReDim Preserve arr2(1 To l)
arr2(l) = str2 '将文件夹和相应的文件存入数组
If filename = "" Then Exit Do
filename = Dir
Loop Until filename = ""
Next