In this article, we’ll learn: How to get all file name from folder in C#.
Path.GetFileName
Returns the file name and extension of the specified path string.
Step1 : Add the namespace to using
1 2 3 |
using System.IO; |
Step 2:
1 2 3 4 5 6 7 8 9 10 11 |
static void Main(string[] args) { DirectoryInfo fileInfo = new DirectoryInfo(@"D:\"); foreach (FileInfo f in fileInfo.GetFiles()) { Console.WriteLine(f.Name); } Console.ReadKey(); } |
Output: