PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2017 how to remove folder name from listbox-VBForums
Results 1 to 2 of 2

Thread: how to remove folder name from listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2019

    how to remove folder name from listbox

    I have a listboxm listing the files in a folder, but I'm new and can't work out how to make the listbox not list the c:\folder1 I have tried a few things...... this is where I am at but does not remove C:\folder1

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: how to remove folder name from listbox

    It would help if you were to show us how you are getting the data and loading it into the ListBox in the first place. In this case, we can probably guess enough but that won't always be the case, so ALWAYS provide a FULL and CLEAR explanation. Maybe there's something relevant in that link but we shouldn't have to download code from a third=party site when you can post the relevant code directly in your thread.

    Anyway, presumably you are calling Directory.GetFiles to get the path of each file in the folder. In that case, you will get the full path of each file as a String. In that case, you can use the Path.GetFileName method to get just the file name from each file path.

    That said, there's a better way. First, create a DirectoryInfo for your folder path. You can then call GetFiles on that to get an array of FileInfo objects. A File Info contains both the full path and also just the name of the file, so you can bind that array to the ListBox and the user will see just the file names, but you can still get the full path of a selection from the SelectedValue. Code:
    1. Dim folder As New DirectoryInfo(folderPath)
    2. Dim files = folder.GetFiles
    4. With ListBox1
    5.     .DisplayMember = "Name"
    6.     .ValueMember = "FullName"
    7.     .DataSource = files
    8. End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width