Public Function GetExtName(strFileName As String) As String
Dim strTmp As String
Dim strByte As String
Dim i As Long
For i = Len(strFileName) To 1 Step -1
strByte = Mid(strFileName, i, 1)
If strByte <>"." Then
strTmp = strByte + strTmp
Else
Exit For
End If
Next i
GetExtName = strTmp
End Function
Public Function search(ByVal strPath As String, Optional strSearch As String) As Boolean
Dim strFile As String
Dim i As Long
Dim lDirCount As Long
On Error GoTo MyErr
If Right(strPath, 1) <>"\" Then strPath = strPath + "\"
Tv1.Nodes.Add , , strPath, strPath, ImageCollapse, ImageExpand
strFile = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
While strFile <>"启数"
DoEvents
If (GetAttr(strPath + strFile) And vbDirectory) <>vbDirectory Then
If LCase(GetExtName(strPath + strFile)) = LCase(GetExtName(strSearch)) Then
Tv1.Nodes.Add strPath, tvwChild, strPath + strFile, strFile, ImageCollapse, ImageExpand
End If
End If
strFile = Dir
Wend
search = True
Exit Function
MyErr:
search = False
End Function
Private Sub Form_Load()
Tv1.Style = 7
search "磨笑D:\Documents\新建文件夹1", ".xls"
search "D:\Documents\新建文件夹2", ".xls"
End Sub
vb.net。通过指定文件夹的路径,获取子文件夹My.Computer.FileSystem.GetDirectories
通过指定文件夹的路径,获取文件名My.Computer.FileSystem.GetFiles。
将不包括路径的文件名和文件夹名增加到treeview中。
TreeView1.Nodes.Add增加一级节点
TreeView1.Nodes(0).Nodes.Add增加第一个一级节点的子节点
TreeView1.SelectedNode.Nodes.Add(“”)增加当历唤前选定节点的子节点
TreeView1.SelectedNode.FullPath返肢运凯回当前选定节点的路径。
要代码可追问,问题再详细具悄脊体些吧。你是要做资源管理器类型的?文件夹和文件都显示在treeview中?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)