I have some .txt files.
The first line of text in each of the files is a number.
I can get a list of all the file names by doing the following:
DirectoryInfo di = new DirectoryInfo(filePath);
FileInfo[] files = di.GetFiles("*.txt");
string[] fileNames = new string[files.Length];
for (int i = 0; i < files.Length; i++)
{
fileNames[i] = files[i].Name;
}
return fileNames.ToList();
I need to sort fileNames based on the number in these files. From lowest to highest.
There are no duplicate, negative, or decimal numbers (so only positive integers).
Also, you can get the number in the files by doing the following:
foreach (string name in names)
{
string[] lines = File.ReadAllLines(filePath + name);
int number = Convert.ToInt32(lines[0]);
}
How do I do this?