Using Directory class library I am trying to retrieve all files Name existing in a Folder as below:
private void button1_Click(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(@"d:\Images\", "*.png");
foreach (string img in filePaths)
{
listBox1.Items.Add(img.ToString());
}
}
As you know this method returns Full path and name of the file but I need to get ONLY the name of files.Is it possible to do this in Directory Class? Do I have to use the Path class for this? if yes, how I can assign a path to a variable without file name?
Thanks,
Try this: