Pages

Monday, 29 January 2018

C# PROGRAM TO GET FILE PATHS IN A GIVEN DIRECTORY

C# PROGRAM TO GET FILE PATHS IN A GIVEN DIRECTORY
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();
            }
        }

    }

}