You apply the Path.GetFileName to the strings returned by the Directory.GetFiles
private void button2_Click(object sender, EventArgs e)
{
string[] path = Directory.GetFiles(@"c:\Users\james.krueger\Desktop\Test Folder\");
foreach (string element in path)
{
lb1.Items.Add(Path.GetFileName(element));
}
}
Path.GetFileName doesn't return the filenames of a directory, but simply extract from a pathname the filename part
However, if your lb1 is a ListBox, you could achieve your result with a very compact code using Linq
string folder = @"c:\Users\james.krueger\Desktop\Test Folder\";
string[] files = Directory.EnumerateFiles(folder).Select(x => Path.GetFileName(x)).ToArray();
lb1.DataSource = files;