c# - Read in from multiple type files all in different locations -


in c# using streamreader, have extract data multiple files. here's code have far. it's not correct , have more specific , add more yet. need select various individual files based on date , time have in common. files common inputted date , time selected extraction. problem files different types e.g. text, xml , html , may possible in different locations. have display extracted data together. appreciated. thank you.

    private void btnload_click(object sender, routedeventargs e)     {         try         {             var files = directory.enumeratefiles("d:\\path", "*.*", searchoption.alldirectories)             .where(s => s.endswith(".txt") || s.endswith(".xml"));              using (streamreader sr = new streamreader("files")).             {                 string line;                  while ((line = sr.readline()) != null)                 {                     lbdisplay.items.add(line);                 }             }         }         catch (exception ex)         {             // let user know went wrong             messagebox.show("the file not read: ");             messagebox.show(ex.message);         }     } 

    ienumerable<string> filecontents = directory.enumeratefiles("e:", "*.*", searchoption.topdirectoryonly)             .select(x => new fileinfo(x))             .where(x => x.creationtime > datetime.now.addhours(-1) || x.lastwritetime > datetime.now.addhours(-1))             .where(x => x.extension == ".xml" || x.extension == ".txt")             .select(file => parsefile(file));      private string parsefile(fileinfo file)     {         using (streamreader sr = new streamreader(file.fullname))         {             string line;             string endresult;             while ((line = sr.readline()) != null)             {                 //logic here determine if correct file , append accordingly                 endresult += line + environment.newline;             }             return endresult;         }     } 

this list of files pass fileinfo object method read contents, need add logic determine if have correct file. if so, start appending lines lbldisplay.


Popular posts from this blog