getting directory list in creation date order
-
Hi guys I have the code to get the directory list of the xml files in an folder but the problem is that i want to get the files in the creation date order. in other words each file has got an date it was created. now i want to load all these xml files into an list array and in the creation date order. is this possible? :confused: my code sofar:
private String\[\] GetDirectory(String XmlFilePath) { List<String> strList = new List<string>(); FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(XmlFilePath); request.Credentials = new NetworkCredential(Username, Password); request.Method = WebRequestMethods.Ftp.ListDirectory; StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()); while (!(sr.EndOfStream)) { strList.Add(sr.ReadLine()); } sr.Close(); sr = null; return strList.ToArray(); }
-
Hi guys I have the code to get the directory list of the xml files in an folder but the problem is that i want to get the files in the creation date order. in other words each file has got an date it was created. now i want to load all these xml files into an list array and in the creation date order. is this possible? :confused: my code sofar:
private String\[\] GetDirectory(String XmlFilePath) { List<String> strList = new List<string>(); FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(XmlFilePath); request.Credentials = new NetworkCredential(Username, Password); request.Method = WebRequestMethods.Ftp.ListDirectory; StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()); while (!(sr.EndOfStream)) { strList.Add(sr.ReadLine()); } sr.Close(); sr = null; return strList.ToArray(); }
i would use something like
string fileName = "/path/to/your/file";
DateTime dt = File.GetCreationTime(fileName);and then work with the returned date depending on how you wanted to order it. have a look at this for some pointers http://stackoverflow.com/questions/844251/how-to-sort-arraylist-of-datetime-objects-in-descending-order[^]