Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting directory list in creation date order

getting directory list in creation date order

Scheduled Pinned Locked Moved C#
data-structuresxmlhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JacquesBrits
    wrote on last edited by
    #1

    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();
        }
    
    T 1 Reply Last reply
    0
    • J JacquesBrits

      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();
          }
      
      T Offline
      T Offline
      tim_gunning
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups