用FSO或其它的方式怎样得到盘下的文件夹的名字

解决方案 »

  1.   

    要得到同一路径下其余文件夹名,直接调用dir即可
      

  2.   

    //遍历所有,你可以在上边改
    Dim BLi As Integer
    Function bianli(path)
    Set fso = CreateObject("scripting.filesystemobject")
    On Error Resume Next
    Set objFolder = fso.GetFolder(path)
    Set objSubFolders = objFolder.Subfolders
        '处理当前目录里的文件
    If BLi = 0 Then
       If Right(path, 1) <> "\" Then path = path & "\"
       Set objFiles = objFolder.Files
         For Each objFile In objFiles
           List1.AddItem path & objFile.Name, 0
         Next
       BLi = 1
    End If
       '处理子目录里的文件
    For Each objSubFolder In objSubFolders
         If Right(path, 1) <> "\" Then
          nowpath = path & "\" & objSubFolder.Name & "\"
         Else
          nowpath = path + objSubFolder.Name + "\"
         End If        Set objFiles = objSubFolder.Files
            For Each objFile In objFiles
             List1.AddItem nowpath & objFile.Name, 0 '增加文件
            Next
        bianli (nowpath) '递归
    Next
    Set objFolder = Nothing
    Set objSubFolders = Nothing
    Set fso = Nothing
    Me.Caption = List1.ListCount
    DoEvents
    End FunctionPrivate Sub Command1_Click()
     bianli ("d:")
    End SubPrivate Sub Form_Unload(Cancel As Integer)
    Unload Form1
    End
    End Sub//也可以在上边加它的判断
    Private Sub Command1_Click()
     Dim BLtext As Integer
     On Error GoTo Errto:
     BLtext = GetAttr(Text1)
     Select Case BLtext
     Case 32
     MsgBox "文件"
     Case 16
     MsgBox "目录"
     Case 0
     MsgBox "没有东东呀!"
     End Select
    Exit Sub
    Errto:
    MsgBox Err.Source & Chr(13) & Err.Description
    Err.Clear
    End Sub
      

  3.   

    怕你改错这个是改好的=======================================================
    Function bianli(path)
    Set fso = CreateObject("scripting.filesystemobject")
    On Error Resume Next
    Set objFolder = fso.GetFolder(path)
    Set objSubFolders = objFolder.Subfolders
       '处理子目录里的文件
    For Each objSubFolder In objSubFolders
         If Right(path, 1) <> "\" Then
          nowpath = path & "\" & objSubFolder.Name & "\"
         Else
          nowpath = path + objSubFolder.Name + "\"
         End If
         List1.AddItem objSubFolder.Name    bianli (nowpath) '递归
    Next
    Set objFolder = Nothing
    Set objSubFolders = Nothing
    Set fso = Nothing
    Me.Caption = List1.ListCount
    DoEvents
    End FunctionPrivate Sub Command1_Click()
     bianli ("d:")
    End SubPrivate Sub Form_Unload(Cancel As Integer)
    Unload Form1
    End
    End Sub