using System;using System.Collections.Generic;using System.Text;using System.IO;namespace Generics{ public class ReadDirectory { #region Member Variable //Directory path given as string. private string directoryPath = @"C:\Session\Help Links"; #endregion #region Constructor public ReadDirectory() { //Below lines to find out whether specified directory //exists or not. DirectoryInfo readDirectory = new DirectoryInfo(directoryPath); if (!readDirectory.Exists) { Console.WriteLine("Directory not found"); return; } //Below line used to read the total files available inside //the specified directory. FileInfo[] filesInDirectory = readDirectory.GetFiles(); //Calling a method by passing name parameter,which //is of type FileInfo[]. ReadFiles(filesInDirectory); } #endregion #region Method - File Reading /// /// Represents the method that reads the full file. /// /// /// The represents the files available in the /// specified directory. /// public void ReadFiles(FileInfo[] fileInDirectory) { //Foreach used to loop thro the each files //present in the directory. foreach (FileInfo files in fileInDirectory) { FileInfo readfile = new FileInfo(files.FullName); if (!readfile.Exists) return; string[] fileLines = File.ReadAllLines(readfile.ToString()); Console.WriteLine("Reading the file " + readfile + "....\n"); //Loop used to read the characters inside a particular file. for (int i = 0; i < fileLines.Length; i++) { Console.WriteLine(fileLines[i]); if (i == fileLines.Length - 1) { Console.WriteLine("End of file" + readfile + ".\n"); } } Console.ReadLine(); } } #endregion }}