Hi... Use below Query to get your desired files type collection:
- string FolderPath = @"D:\AllFiles";
- DirectoryInfo di = new DirectoryInfo(FolderPath)
-
-
- List getAllCSVFiles = di.GetFiles("*.csv")
- .Where(file => file.Name.EndsWith(".csv"))
- .Select(file => file.Name).ToList();
-
-
- List getAllNotePadFiles = di.GetFiles("*.txt")
- .Where(file => file.Name.EndsWith(".txt"))
- .Select(file => file.Name).ToList();
Just pass your file extension and enjoy