-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
54 lines (49 loc) · 1.68 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
namespace C_ConsoleApp_FileReader
{
class Program
{
static void Main(string[] args)
{
//string directoryPath = @"E:\\Job Interview helper\\Filereader\\";
Console.Write("Enter Directory path: ");
string directoryPath;
try
{
directoryPath = Console.ReadLine();
if (Directory.Exists(directoryPath))
fileReader(directoryPath);
else
{
Console.Write("No path exist.\nEnter new Directory path:");
directoryPath = Console.ReadLine();
fileReader(directoryPath);
}
}
catch (NullReferenceException e)
{
Console.WriteLine("Path is null. Exception " + e);
}
}
//File Reader function
public static void fileReader(string folder)
{
//Filtering txt file
string[] filePaths = Directory.GetFiles(folder, "*.txt", SearchOption.AllDirectories);
foreach (string filePath in filePaths)
{
//Print file path
Console.WriteLine("\nFILE PATH - " + filePath);
//Print file name
Console.WriteLine("\tFILE NAME - " + Path.GetFileName(filePath));
//Print file content
string[] lines = File.ReadAllLines(filePath);
Console.Write("\tFILE CONTENT - ");
foreach (string line in lines)
Console.Write(line + " ");
Console.WriteLine("\n");
}
}
}
}