I have a dictionary. Everything is working fine but sorting. I have even tried a SortedDictionary.
Here's what I am doing, I have a Dictionary that contains FilePath,FileName alright.
Well I am trying to sort by the Value and then put then put the (Keys) into a list.
Here is my code. (UPDATED: ENTIRE METHOD).
public static void DisplayScriptListNames(){
scriptsList.Clear ();
fileInfo = new DirectoryInfo (Application.dataPath);
if (EclecticGlobalSettings._cSharp && isSharp) {
sharpFiles = fileInfo.GetFiles ("*.cs", SearchOption.AllDirectories).ToList();
} if(EclecticGlobalSettings._usScripts && !isSharp) {
javaFiles = fileInfo.GetFiles ("*.js", SearchOption.AllDirectories).ToList();
}
if (EclecticGlobalSettings._cSharp && isSharp) {
// C#
if (sharpFiles.Count != 0) {
foreach (FileInfo i in sharpFiles){
string line = i.Name.ToString ();
string checkPath = Path.GetDirectoryName (i.FullName);
string assetsPath = checkPath.Substring (i.FullName.IndexOf ("Assets"));
if (!assetsPath.Contains("Editor") && !assetsPath.Contains("Standard Assets")) {
scriptDictionary.Add(i.FullName,i.Name);
scriptsFound += 1;
}
}
}
}
if(EclecticGlobalSettings._usScripts && !isSharp){
//JS
foreach (FileInfo i in javaFiles) {
//string line = i.FullName.ToString ();
string line = i.Name.ToString ();
string checkPath = Path.GetDirectoryName (i.FullName);
string assetsPath = checkPath.Substring (i.FullName.IndexOf ("Assets"));
if (!assetsPath.Contains("Editor") && !assetsPath.Contains("Standard Assets")) {
Debug.Log (i.Name);
scriptDictionary.Add(i.FullName,i.Name);
scriptsFound += 1;
}
}
}
foreach (KeyValuePair<string,string> item in scriptDictionary.OrderBy(key=>key.Value)) {
Debug.Log (item);
scriptsList.Add (item.Key);
}
//scriptsList.AddRange (scriptDictionary.Keys);
//scriptsList.Sort (Path.GetFileName);
//foreach (string ii in scriptsList) {
// Debug.Log (ii);
//
//}
}
Okay, the Debug.Log() is Unity's way of a Console.WriteLine. And it does in fact say it's sorting it. But when I do.
scriptsList.Add (item.Key);
It's unorganized as it was before. Is there some simple little step I am missing? Because the console does in fact say it's sorted perfectly the way I'd like. But for some reason, the scriptsList.Add(item.key) < For the PATH to the file. Says it isn't sorted.
I would do scriptList.Sort(); But remember, the scriptList is the keys (File Paths). Which is why I've been trying to sort via Values (the file names).
Which again, says it does sort them.
Here's an example of what compiler says
C:/Cat.txt, Cat.txt.
C:/Dog.txt, Dog.txt.
C:/Wolf.txt, Wolf.txt.
But when I go to add them to the list.
C:/Wolf.txt.
C:/Dog.txt.
C:/Cat.txt.