• Log in or sign up for an account here: https://www.sythe.org/login

pulling info from file folders to program

  • Thread starter Thread starter alexandr
  • Start date Start date
A

alexandr

Guest
pulling info from file folders to program
how do you pull information from file folders to the program, ex. the items that are in the list box on program startup are items from a file folder. if you dont understand just tell me.. ill try to explain better.
 
pulling info from file folders to program
Well, if you haven't figured this out yet, this should help a bit.

What's needed:

1 Form named Form1

1 Listbox named lbxFiles

1 Folder in the C drive labeled "Test Folder" (pretty much any folder will work)

Code:
Imports System.IO

Public Class Form1
    Private dir As New IO.DirectoryInfo("C:\Test Folder")     'Change the folder path as needed
    Private fileArray As IO.FileInfo() = dir.GetFiles("*.*")  'Change *.* to filter file extensions/names, ex. *.txt, *.bmp  or asdf.*
    Private file As IO.FileInfo


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each Me.file In Me.fileArray
            lbxFiles.Items.Add(Me.file.FullName)
        Next
    End Sub

    Private Sub lbxFiles_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbxFiles.DoubleClick
        If (lbxFiles.SelectedIndex >= 0) Then
            Dim proc As New Process
            Dim procInfo As New ProcessStartInfo

            procInfo.FileName = lbxFiles.SelectedItem.ToString
            procInfo.UseShellExecute = True

            proc.StartInfo = procInfo
            proc.Start()
        End If
    End Sub
End Class

Well, that is it. I added the double-click event handler so that the program is somewhat useful. If you could elaborate on what you want to do with the listbox items or the desired file types, that would help. Also, if you don't want to change the source to edit the folder path, then just add a folder browser dialog and set the [dialogName].selectedpath to a variable and pass it to IO.DirectoryInfo([pathVariable]).

Hope this helped.
 
Runescape Gamblingrunescape gambling
Back
Top