Dim FsoFolders As Folder Dim FsoFolder As Folder Dim FsoDrives As Drives Dim FsoDrive As Drive Dim Fso As FileSystemObject Dim R As String Dim nodX As Node Dim nod As NodePrivate Sub Form_Load() R = "Root" Set nodX = TreeView1.Nodes.Add(, , R, "文件系统") Set Fso = CreateObject("Scripting.FileSystemObject") Set FsoDrives = Fso.Drives For Each FsoDrive In FsoDrives Set nod = TreeView1.Nodes.Add(R, 4, FsoDrive.path, FsoDrive.path & "\") If FsoDrive.DriveType <> CDRom Then FileTree2 nod.Key + "\", FsoDrive.path End If Next nod.EnsureVisible End SubPrivate Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) If Node.Text = "文件系统" Then Exit SubFileTree Node.Key & "\", Node.KeyEnd Sub Private Function FileTree(ByVal path As String, ByVal NodeKey As String) As Long On Error Resume Next Debug.Print path Set FsoFolders = Fso.GetFolder(path) For Each FsoFolder In FsoFolders.SubFolders Set nod = TreeView1.Nodes.Add(NodeKey, 4, FsoFolder.path, FsoFolder.Name) FileTree2 FsoFolder.path + "\", FsoFolder.path NextEnd Function Private Function FileTree2(ByVal path As String, ByVal NodeKey As String) As Long On Error Resume NextSet FsoFolders = Fso.GetFolder(path) For Each FsoFolder In FsoFolders.SubFolders Set nod = TreeView1.Nodes.Add(NodeKey, 4, FsoFolder.path, FsoFolder.Name) NextEnd Function
Dim FsoFolder As Folder
Dim FsoDrives As Drives
Dim FsoDrive As Drive
Dim Fso As FileSystemObject
Dim R As String
Dim nodX As Node
Dim nod As NodePrivate Sub Form_Load()
R = "Root"
Set nodX = TreeView1.Nodes.Add(, , R, "文件系统")
Set Fso = CreateObject("Scripting.FileSystemObject")
Set FsoDrives = Fso.Drives
For Each FsoDrive In FsoDrives
Set nod = TreeView1.Nodes.Add(R, 4, FsoDrive.path, FsoDrive.path & "\")
If FsoDrive.DriveType <> CDRom Then
FileTree2 nod.Key + "\", FsoDrive.path
End If
Next
nod.EnsureVisible
End SubPrivate Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If Node.Text = "文件系统" Then Exit SubFileTree Node.Key & "\", Node.KeyEnd Sub
Private Function FileTree(ByVal path As String, ByVal NodeKey As String) As Long
On Error Resume Next
Debug.Print path
Set FsoFolders = Fso.GetFolder(path)
For Each FsoFolder In FsoFolders.SubFolders
Set nod = TreeView1.Nodes.Add(NodeKey, 4, FsoFolder.path, FsoFolder.Name)
FileTree2 FsoFolder.path + "\", FsoFolder.path NextEnd Function
Private Function FileTree2(ByVal path As String, ByVal NodeKey As String) As Long
On Error Resume NextSet FsoFolders = Fso.GetFolder(path)
For Each FsoFolder In FsoFolders.SubFolders
Set nod = TreeView1.Nodes.Add(NodeKey, 4, FsoFolder.path, FsoFolder.Name)
NextEnd Function
dir /a /s /b c:\*.* >c:\1.txt
tree/?
自己看吧
dir c: /s >c:\1.txt
dir c: /ad /s >c:\1.txt