VB 枚举目录

来源:百度知道 编辑:UC知道 时间:2024/06/13 14:35:47
如题~用循环
AlphaBlend 你的代码不行啊~If (GetAttr(FullPathName(sPath) & item) And vbDirectory) = vbDirectory Then
错误的文件号 或者 文件未找到

function FileEnum(a)
Debug.Print a'添加被枚举文件的处理代码
end function

function FolderEnum(a)
Debug.Print a'添加被枚举目录的处理代码
end function

function EnumFolder(byval g)
If IsEmpty(fso) Then set fso=createobject("Scripting.FileSystemObject")
set g=fso.getfolder(g)
FolderEnum g
for each t in g.files '只枚目录举删掉这个for
FileEnum t
next
for each t in g.subfolders
EnumFolder t
next
end function
========================
用法:EnumFolder "E:\新建文件夹"

Public Function GetAllDirs(ByVal sPath As String)
Dim item As String
Dim oPaths As New Collection

item = Dir(sPath, vbDirectory)

While Len(item) > 0
If item <> "." And item <> ".." Then
If (GetAttr(FullPathName(sPath) & item) And vbDirectory) = vbDirectory Then
oPaths.Add item
Debug.Print sPath & item
Else
End If
End If
<