As Ak

As Ak

  • NA
  • 65
  • 7.6k

How to read the data in the .txt file from 4 different paths

Sep 28 2020 9:01 PM
I need to read the data in the .txt file in the folders from 4 different paths. I've done the code, but it only read the data from the first folder.
 
How can I read the data in the folder from different paths?
 
This is my code:
  1. private void readData()  
  2. {  
  3. string[] Comp = new[] { "A001""A002""A003""A004" };  
  4. string Comps= Comp[0];  
  5. string Path = $@"Z:\IT\Shares\PC\PC-{Comp}\SS\Data\{Comp}_DataFile.txt";  
  6.   
  7. //read and get details  
  8. var data = File  
  9. .ReadAllLines(Path)  
  10. .Select(x => x.Split('='))  
  11. .Where(x => x.Length > 1)  
  12. .ToDictionary(x => x[0].Trim(), x => x[1]);  
  13. Console.WriteLine("Name: {0}", data["Name"]);  
  14. Console.WriteLine("Age: {0}", data["Age"]);  
  15. }  

Answers (3)