[RESOLVED] [2005] Putting folde contents names into a text box?r
hey, im writing a program that has a button which opens up a folder browser dialog, then the user chooses a folder and the names of the files in that folder are put into a text box, i dont need the file extension to be printed there, just the file names and extensions.
does anyone have any idea on how i will be able to do this?
thanks in advanced
Re: [2005] Putting folde contents names into a text box?r
You don't need the file extension, just the file names and extensions? That doesn't make much sense to me.
Re: [2005] Putting folde contents names into a text box?r
Code:
Dim di As New IO.DirectoryInfo(FolderDialog1.SelectedPath)
Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
For Each fi In aryFi
If TextBox1.MultiLine = True Then
TextBox1.Text = TextBox1.Text & vbCrlf & fi.Name.Replace(fi.Extension,"")
Else
TextBox1.Text = TextBox1.Text & " | " & fi.Name.Replace(fi.Extension,"")
End If
Next
Re: [2005] Putting folde contents names into a text box?r
sorry lol i ment i didnt need file paths lol just file names and extensions
Re: [2005] Putting folde contents names into a text box?r
and ty for the code, but VS seems to have a problem with it when i click the addfile button the program crashes and;
"di As New IO.DirectoryInfo(dlgBrowse.SelectedPath)"
is highlighted with the exception;
"path is not of a legal form"
any ideas on that?
thanks all help is appreciated
Re: [2005] Putting folde contents names into a text box?r
What have you got the initial directory set as?
Re: [2005] Putting folde contents names into a text box?r
vb Code:
Imports System.IO
Public Class frmBrowser
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
Dim di As New IO.DirectoryInfo(dlgBrowse.SelectedPath)
Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
For Each fi In aryFi
If txtFolders.Multiline = True Then
txtFolders.Text = txtFolders.Text & vbCrLf & fi.Name.Replace(fi.Extension, "")
Else
txtFolders.Text = txtFolders.Text & " | " & fi.Name.Replace(fi.Extension, "")
End If
Next
End Sub
End Class
thats wot i got completely lol
Re: [2005] Putting folde contents names into a text box?r
i think i found the problem
Re: [2005] Putting folde contents names into a text box?r
i managed to solve it lol im a dumbass i hadnt launched the dialog so what was the selected path supposed to be, no wonder the error lol, thanks for all the help :)