C# PROGRAM TO GET FILE PATHS IN A GIVEN DIRECTORY
C# PROGRAM TO GET ALL FILE PATHS IN A GIVEN DIRECTORY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
using System; using System.IO; namespace GetFileNames { class Program { static void Main(string[] args) { try { string FolderPath ; string[] Files; Console.WriteLine(" Enter the Directory Path to get File Names in it : "); FolderPath=Console.ReadLine(); Files = Directory.GetFiles(FolderPath); Console.WriteLine("\n The FilePaths in given Directory are : \n\n"); foreach (string FileName in Files) { Console.WriteLine(FileName); } Console.ReadLine(); } catch (DirectoryNotFoundException ex) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("\n\n Directory Not Found..Press any key to exit..."); Console.ReadKey(); } } } } |
Sample Output 1 :
Sample Output 2 :