I
Igor-Duarte
Guest
I have a file explorer in vb.net and I put a field and a button that for when I type in this field a name of a folder, document, image or any other file and click the button, it searches for that file and if it does not find the file it shows the files with the same name, or no case has no file with the name entered, exactly like the file explorer that Windows has.
link image
https://social.msdn.microsoft.com/Forums/getfile/1446035
I am putting the whole code of the project for a better understanding of how my code works.
Imports System.IO
Public Class Form1
Dim path As String
Dim nextPath As String
Public Property ListView1 As Object
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
path = TextBox1.Text
If (My.Computer.FileSystem.DirectoryExists(path)) Then
explorer.Clear()
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Else
MsgBox("Its A File")
'or user
'pocess.Start(path) // to open the file
End If
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
path = "C:\Program Files (x86)"
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Catch ex As Exception
MsgBox("Não foi encontrado o caminho 'C:\Program Files (x86)' na rede. Entre em contato com o setor de TI.")
Application.Exit()
End Try
End Sub
Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles explorer.ItemSelectionChanged
nextPath = path + "\" + e.Item.Text
End Sub
Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles explorer.MouseDoubleClick
Try
If (My.Computer.FileSystem.DirectoryExists(nextPath)) Then
path = nextPath
explorer.Clear()
TextBox1.Text = path
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Else
Process.Start(path & "\" & explorer.SelectedItems(0).Text)
End If
Catch ex As Exception
MsgBox("Voçe não tem acesso a esse arquivo, feche o aplicativo e abra o novamente.")
End Try
End Sub
Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
Try
nextPath = path.Substring(0, path.LastIndexOf("\"))
path = nextPath
explorer.Clear()
TextBox1.Text = path
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Catch ex As Exception
MsgBox("Não é possivel voltar mais, o aplicativo 'Instruções de Trabalhos Técnicos' irá reiniciar.")
Application.Restart()
End Try
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
End Class
And here is the command of the field to type and the command of the button:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Can you help me?
Continue reading...
link image
https://social.msdn.microsoft.com/Forums/getfile/1446035
I am putting the whole code of the project for a better understanding of how my code works.
Imports System.IO
Public Class Form1
Dim path As String
Dim nextPath As String
Public Property ListView1 As Object
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
path = TextBox1.Text
If (My.Computer.FileSystem.DirectoryExists(path)) Then
explorer.Clear()
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Else
MsgBox("Its A File")
'or user
'pocess.Start(path) // to open the file
End If
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
path = "C:\Program Files (x86)"
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Catch ex As Exception
MsgBox("Não foi encontrado o caminho 'C:\Program Files (x86)' na rede. Entre em contato com o setor de TI.")
Application.Exit()
End Try
End Sub
Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles explorer.ItemSelectionChanged
nextPath = path + "\" + e.Item.Text
End Sub
Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles explorer.MouseDoubleClick
Try
If (My.Computer.FileSystem.DirectoryExists(nextPath)) Then
path = nextPath
explorer.Clear()
TextBox1.Text = path
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Else
Process.Start(path & "\" & explorer.SelectedItems(0).Text)
End If
Catch ex As Exception
MsgBox("Voçe não tem acesso a esse arquivo, feche o aplicativo e abra o novamente.")
End Try
End Sub
Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
Try
nextPath = path.Substring(0, path.LastIndexOf("\"))
path = nextPath
explorer.Clear()
TextBox1.Text = path
For Each i In My.Computer.FileSystem.GetDirectories(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)
Next
For Each i In My.Computer.FileSystem.GetFiles(path)
explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
Next
Catch ex As Exception
MsgBox("Não é possivel voltar mais, o aplicativo 'Instruções de Trabalhos Técnicos' irá reiniciar.")
Application.Restart()
End Try
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
End Class
And here is the command of the field to type and the command of the button:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Can you help me?
Continue reading...