I used this code to get the contents of a directory:
string[] savefile = Directory.GetFiles(mcsdir, "*.bin");
comboBox1.Items.AddRange(savefile);
and it returns as
C:\Users\Henry\MCS\save1.bin
C:\Users\Henry\MCS\save2.bin
How can I make it return as only
save1.bin
save2.bin
Please note that this app will be used by other people, so the name is not always “Henry”.
Thank you.
Use LINQ:
Looking at the suggestion of minitech:
As long as you get the array of type
FileInfo[]there is no need to convert it to string array. Just set the propertyDisplayMemberto the property name you want to display in yourComboBox.Using this you keep your original
FileInfo[]array with all additional information (as to the full path to your files) and same time display only the short filenames (without path) in your control.(I assume that your question is about WinForms. If you are using Silverlight or WPF you need to set the property using the “Target” attribute).