This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

10 Mar 2013

C# PROGRAM TO GET FILE PATHS IN A GIVEN DIRECTORY

C# PROGRAM TO GET ALL FILE PATHS IN A GIVEN DIRECTORY

original post

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 :


No comments:

Post a Comment

Thanks for your comments.
-Sameer