I'm very new to c# and am working on a project where I need to search through a directory for specific document types and record the names of all of them. With these document names I then need to check that they all start with an ID in the form xxxx-xxxx-xxxxxx-xxx-xxx and save only the ones that both of these statements are true.
I use :
var filesToBeRead = Directory.GetFiles(FBD.SelectedPath, "*.*", SearchOption.AllDirectories)
.Where(s => s.EndsWith(".txt") || s.EndsWith(".docx") || s.EndsWith(".doc")|| s.EndsWith(".xls") || s.EndsWith(".docm") || s.EndsWith(".xlsm") || s.EndsWith(".xlsx"));
To get all the files in my specified directory and save them to an IEnumerable string. I then copy this to a list because I think that a list would be easier to manipulate. (I'm not sure if they are actually just the same thing and I'm making extra work for myself).
var allFiles = new List<string>();
allFiles = filesToBeRead.ToList();
Then from here I'm not really sure what to do. My idea is: since xxxx-xxxx-xxxxxx-xxx-xxx is the format I'm looking for at the start of each document name and it is 24 chars long that I would search for the 25th char and copy everything in the string before that. I'm not entirely sure how to do this and more specifically I'm not sure how to loop through the list and copy that every time.
My idea is to use a foreach but I'm not sure how to specify that I'm looking for the 25th char and copy everything before that.
Any help or direction to a web page to read into how to do this would be greatly appreciated.