Skip to content

Instantly share code, notes, and snippets.

@Generickle
Created December 21, 2018 20:42
Show Gist options
  • Save Generickle/e1ff8f0b5991302c817dfc48c099674e to your computer and use it in GitHub Desktop.
Save Generickle/e1ff8f0b5991302c817dfc48c099674e to your computer and use it in GitHub Desktop.
Explorador de Archivo usando TreeView
'Evento generado por un botón en la interfaz que actualiza el arbol
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListarDirectorios(treeView, "C:\Users\Erick Dávila\Documents\USAC\FISQL-OLC2-DIC-2018\OLC2-P1-Servidor-de-Base-de-Datos\OLC2-P1-Servidor-de-Base-de-Datos\bin\Debug\DBMS")
End Sub
'Evento que abre el archivo al darle doble click en una nueva pestaña
Private Sub treeView_DoubleClick(sender As Object, e As EventArgs) Handles treeView.DoubleClick
Try
OpenFileDesdeArbol()
Catch ex As Exception
MessageBox.Show("Ahhhhhhh", "ÁRBOL CORTADO")
End Try
End Sub
'Recorrido de la ruta indicada
Private Sub ListarDirectorios(ByVal treeView As TreeView, ByVal path As String)
treeView.Nodes.Clear()
treeView.ImageList = imageList1
Dim root = New DirectoryInfo(path)
treeView.Nodes.Add(CrearNodoDirectorio(root))
End Sub
Private Function CrearNodoDirectorio(ByVal directoryInfo As DirectoryInfo) As TreeNode
Dim nodoDirectorio = New TreeNode(directoryInfo.Name, 1, 1)
For Each directory In directoryInfo.GetDirectories()
nodoDirectorio.Nodes.Add(CrearNodoDirectorio(directory))
Next
For Each file In directoryInfo.GetFiles()
Dim nodo As TreeNode
If file.Name.EndsWith(".xml") Then
nodo = New TreeNode(file.Name, 3, 3)
Else
nodo = New TreeNode(file.Name, 0, 0)
End If
nodoDirectorio.Nodes.Add(nodo)
Next
Return nodoDirectorio
End Function
'Valida el tipo de extensión y la ubación del archivo (Esto está quemado XD)
Private Sub OpenFileDesdeArbol()
Dim TreeNodeName As String = treeView.SelectedNode.ToString().Replace("TreeNode: ", String.Empty)
If treeView.SelectedNode.Nodes.Count = 0 Then
If TreeNodeName.EndsWith(".usql") Then
Dim ruta As String = "C:\Users\Erick Dávila\Documents\USAC\FISQL-OLC2-DIC-2018\OLC2-P1-Servidor-de-Base-de-Datos\OLC2-P1-Servidor-de-Base-de-Datos\bin\Debug\DBMS\Scripts\" & TreeNodeName
LoadDataFromFileTab(ruta)
ElseIf TreeNodeName.EndsWith(".xml") Then
Dim carpeta As String = TreeNodeName.Substring(0, TreeNodeName.Length - 3)
Dim ruta As String = "C:\Users\Erick Dávila\Documents\USAC\FISQL-OLC2-DIC-2018\OLC2-P1-Servidor-de-Base-de-Datos\OLC2-P1-Servidor-de-Base-de-Datos\bin\Debug\DBMS\Bases de Datos\" & carpeta & "\" & TreeNodeName
LoadDataFromFileTab(ruta)
Else
System.Diagnostics.Process.Start("C:/Users/Erick Dávila/Documents/USAC/FISQL-OLC2-DIC-2018/OLC2-P1-Servidor-de-Base-de-Datos/OLC2-P1-Servidor-de-Base-de-Datos/bin/Debug/DBMS/" & TreeNodeName)
End If
End If
End Sub
'Agrega la nueva pestaña con el contenido del archivo
Private Sub LoadDataFromFileTab(ByVal path As String)
If File.Exists(path) Then
addTab("USQL", "", "")
updateTab(getTabActual(), System.IO.Path.GetFileName(path), path, File.ReadAllText(path))
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment