不用FSO,用API是否能列出指定目录下的文件或文件夹??到ListBox控件中用FSO是能做到,但觉得...呵呵.
如果不用,是否能做呢?用API可以不?

解决方案 »

  1.   

    '模 块 名:GetFolderList
    '功    能:返回指定文件夹的所有文件夹列表
    '返 回 值:成功/失败:True/False
    '参    数:GetFileList(指定文件夹路径, 文件夹数组)
    '引    用:无
    '外部函数:无
    '内部变量:[SearchDir=路径][FoundDir=文件夹名][i=用于循环]
    '调用方法:
    '++++++++++++++++++++++++++++++++++++
    '   Dim FolderName() As String, i As Long
    '   GetFolderList "C:\", FolderName
    '   For i = LBound(FolderName) To UBound(FolderName)
    '       Debug.Print FolderName(i)
    '   Next i
    '++++++++++++++++++++++++++++++++++++
    Public Function GetFolderList(ByVal Path As String, ByRef FolderName() As String) As Boolean
        Dim SearchDir As String
        Dim FoundDir As String
        Dim i As Long
        If right(Path, 1) <> "\" Then Path = Path & "\"
        SearchDir = Path & "*."
        FoundDir = Dir(SearchDir, vbDirectory)
        While FoundDir <> ""
            If Not FoundDir = "." Or FoundDir = ".." Then
                ReDim Preserve FolderName(i) As String
                FolderName(i) = FoundDir
            End If
            FoundDir = Dir()
            i = i + 1
        Wend
    End Function'模 块 名:GetFileList
    '功    能:返回指定文件夹的所有文件名列表
    '返 回 值:成功/失败:True/False
    '参    数:GetFileList(指定文件夹路径, 文件数组,返回的文件类型)
    '引    用:无
    '外部函数:无
    '内部变量:[fName=文件名][i=用于循环]
    '调用方法:
    '++++++++++++++++++++++++++++++++++++
    '   Dim FileName() As String, i As Long
    '   GetFileList "c:\", FileName
    '   For i = 0 To UBound(FileName)
    '       Debug.Print FileName(i)
    '   Next i
    '++++++++++++++++++++++++++++++++++++
    Function GetFileList(ByVal Path As String, ByRef Filename() As String, Optional fExp As String = "*.*") As Boolean
        Dim fName As String, i As Long
        If right$(Path, 1) <> "\" Then Path = Path & "\"
        fName = Dir$(Path & fExp)
        i = 0
        Do While fName <> ""
            ReDim Preserve Filename(i) As String
            Filename(i) = fName
            fName = Dir$
            i = i + 1
        Loop
        If i <> 0 Then
            ReDim Preserve Filename(i - 1) As String
            GetFileList = True
        Else
            GetFileList = False
        End If
    End Function
    --------------
    老问题了,看下FAQ啊。