TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Find Total Number of Lines in a File using C#
Bhushan Gawale
May 16
2016
Code
1.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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