C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Find Total Number of Lines in a File using C#
WhatsApp
Bhushan Gawale
May 16
2016
1.3
k
0
0
try
{
Console.WriteLine(
"enter folder path: "
);
string
folderPath = Console.ReadLine();
DirectoryInfo dirInfo =
new
DirectoryInfo(folderPath);
if
(dirInfo !=
null
)
{
FileInfo[] allFiles = dirInfo.GetFiles();
if
(allFiles !=
null
&& allFiles.Count() > 0)
{
foreach
(var file
in
allFiles)
{
Console.WriteLine(File.ReadLines(file.FullName).Count());
}
}
}
}
catch
(Exception ex)
{
Console.WriteLine(
"Error.."
+ ex.Message);
}
finally
{
Console.WriteLine(
"Enter to exit.."
);
Console.ReadLine();
}
C#
count
Up Next
Find Total Number of Lines in a File using C#