Create a File Explorer in VB.net (Part 1/2) - decliciousVB

deliciousVB
deliciousVB
16 هزار بار بازدید - 11 سال پیش - Hey again guys its deliciousVB
Hey again guys its deliciousVB with another tutorial. This one is an in depth explanation of a file explorer code, part 1/2.

Part two is here: Part 2 - Create a File Explorer in VB...
Make sure to rate, comment and subscribe if you want to see more! (Codes below)



CODES:
Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Populate(ComboBox1.Text)
   End Sub

   Private Sub Populate(ByVal path As String)
       Try
           ListView1.Items.Clear()
           ComboBox1.Text = path

           Dim lb As New ListBox

           For Each str As String In My.Computer.FileSystem.GetDirectories(path)
               lb.Items.Add(str)
           Next

           For Each str As String In My.Computer.FileSystem.GetFiles(path)
               lb.Items.Add(str)
           Next

           ListView1.Items.Add("...")

           For Each item In lb.Items
               Dim NewItem As New ListViewItem
               If My.Computer.FileSystem.FileExists(item.ToString) Then
                   Dim info As New System.IO.FileInfo(item.ToString)
                   NewItem.Text = item.ToString
                   NewItem.SubItems.Add(info.Length)
                   NewItem.SubItems.Add(info.CreationTime)
                   NewItem.SubItems.Add(info.LastWriteTime)
               Else
                   Dim info As New System.IO.DirectoryInfo(item.ToString)
                   NewItem.Text = item.ToString
                   NewItem.SubItems.Add("Directory")
                   NewItem.SubItems.Add(info.CreationTime)
                   NewItem.SubItems.Add(info.LastWriteTime)
               End If
               ListView1.Items.Add(NewItem)
           Next
           ComboBox1.Items.Add(path)
       Catch ex As Exception
           If path.EndsWith("My Documents") Then
               path = My.Computer.FileSystem.SpecialDirectories.MyDocuments
               Populate(path)
           ElseIf path.EndsWith("My Pictures") Then
               path = My.Computer.FileSystem.SpecialDirectories.MyPictures
               Populate(path)
           ElseIf path.EndsWith("My Music") Then
               path = My.Computer.FileSystem.SpecialDirectories.MyMusic
               Populate(path)
           End If
       End Try
   End Sub

   Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
       If My.Computer.FileSystem.FileExists(ListView1.FocusedItem.Text) Then
           Process.Start(ListView1.FocusedItem.Text)
       Else
           If ListView1.FocusedItem.Text = "..." Then
               Try
                   Populate(My.Computer.FileSystem.GetParentPath(ComboBox1.Text))
               Catch ex As Exception
                   MsgBox("You can't get any farther back than a drive! (" & ComboBox1.Text & ")")
               End Try
           Else
               Populate(ListView1.FocusedItem.Text)
           End If
       End If
   End Sub

   Private Sub ComboBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
       If e.KeyCode = Keys.Enter Then
           Try
               Populate(ComboBox1.Text)
           Catch ex As Exception
               MsgBox(ComboBox1.Text & " does not exist on this system as a directory. Check spelling.")
           End Try
       End If
   End Sub
End Class
11 سال پیش در تاریخ 1392/11/01 منتشر شده است.
16,014 بـار بازدید شده
... بیشتر