public myFile[] getFilebyCreationtime(String path) { myFile[] result = null; try { DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] inf = dir.GetFiles(); DirectoryInfo[] subdirs = dir.GetDirectories(); result = new myFileSortCreationTime[inf.Length + subdirs.Length]; //add the dirs to the result for (int i = 0; i < subdirs.Length; i++) { result[i] = new myFileSortCreationTime(true, subdirs[i].Name, 0, subdirs[i].CreationTime.ToString()); } //add the files to the result for (int i = 0; i < inf.Length; i++) { result[i + subdirs.Length] = new myFileSortCreationTime(false, inf[i].Name, inf[i].Length, inf[i].CreationTime.ToString()); } Array.Sort(result); return(result); } catch (DirectoryNotFoundException) { result = new myFile[1]; result[0] = new myFile(false, "Directory is Not Found.Please Check your Path and try again.", 0, ""); return(result); } }
public int CompareTo(object obj) { myFileSortCreationTime m = obj as myFileSortCreationTime; if (m == null) { throw new NotImplementedException(); } return(this.getCreateTime().CompareTo(m.getCreateTime())); }