C# Corner
Tech
News
Videos
Forums
Trainings
Books
Live
More
Interviews
Events
Jobs
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
Get Files List From Directory In C#
WhatsApp
Yogeshkumar Hadiya
5y
65.6
k
0
5
25
Blog
In this blog, we will create a C# program that prints a list of all files from a particular directory with the file name.
Files In Directory
Code
using
System;
using
System.IO;
namespace
GetFileFromDirectory
{
class
Program
{
static
void
Main(
string
[] args)
{
DirectoryInfo d =
new
DirectoryInfo(@
"E:\Movies"
);
FileInfo[] Files = d.GetFiles();
Console.WriteLine(
"Files in this directory."
);
Console.WriteLine(
"---------------------------------------------------------------------------------------"
);
foreach
(FileInfo file
in
Files)
{
Console.WriteLine(
"File Name : {0}"
, file.Name);
}
Console.ReadKey();
}
}
}
Explanation
In the above code, we get directory/folder info bypassing our folder path in DirectoryInfo Constructor.
Then we create an array of FileInfo and get all files that are in our directory by our variable d.
Then iterate that FileInfo array and print file name one by one.
Output
People also reading
Membership not found