Yogesh Vedpathak

Yogesh Vedpathak

  • 678
  • 1.4k
  • 191.2k

read a textfile line by line and search into folder

Jul 10 2018 4:29 AM
read a textfile line by line and search into folder that filename exist into folder or not ?
i am putting filename into one textfile my program read this file and display filenames ...
want to implement when one line is read from textfile seach that name of file is exist into folder or not ...
 
Here is my code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Text;  
  6. namespace ReadFIles  
  7. {  
  8. class Program  
  9. {  
  10. static void Main(string[] args)  
  11. {  
  12. int counter = 0;  
  13. string line ;  
  14. // Read the file and display it line by line.  
  15. System.IO.StreamReader file =  
  16. new System.IO.StreamReader(@"C:\FtpBackup\Yogesh.txt");  
  17. string File2 = @"C:\FtpBackup\Ndata";  
  18. while ((line = file.ReadLine()) != null)  
  19. {  
  20. System.Console.WriteLine(line);  
  21. counter++;  
  22. // string Userinput = line;  
  23. //string filePresentCK = file2 + Userinput;  
  24. //if (File.Exists(filePresentCK))  
  25. //{  
  26. // Console.Write("File Found");  
  27. //}  
  28. //else  
  29. //{  
  30. // Console.Write("File Not Found");  
  31. //}  
  32. //if (!Directory.Exists(@"C:\FtpBackup\" + line))  
  33. //{  
  34. // Console.WriteLine("File Exist");  
  35. //}  
  36. }  
  37. file.Close();  
  38. System.Console.WriteLine("There were {0} lines in a Filename.txt .", counter);  
  39. // Suspend the screen.  
  40. System.Console.ReadLine();  
  41. }  
  42. }  
  43. }  

Answers (5)