Search This Blog

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

C# PROGRAM TO GET FILE PATHS IN A GIVEN DIRECTORY


C# PROGRAM TO GET ALL 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();
            }
        }

    }
}

Sample Output1 :

Sample Output2 :



15 comments:

  1. Good post! Thanks for sharing this information. I appreciate it. It is very beneficial for visitors.Visit: Sense

    ReplyDelete
  2. nice article .thank you for sharing useful info.
    web programming tutorial
    welookups

    ReplyDelete
  3. This is an best post. It is Really very informative concept.I like it and help me to development very well.Thanks alot for this brief explanation and very nice information.C#.NET Course In Hyderabad

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. I got what i am seraching from last few days in your Blog. I hope you will share more info about it. Please keep sharing.
    Laptop Service center in Ameerpet
    Dell Service center in Ameerpet
    HP Service center in Ameerpet
    Lenovo Service center in Ameerpet

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Here is the site(bcomexamresult.in) where you get all Bcom Exam Results. This site helps to clear your all query.
    BA 3rd year Result 2019-20
    Kumaun University BCOM 3rd Year Result 2020

    ReplyDelete
  11. Bollywood News in Hindi - Check out the latest Bollywood news, new Hindi movie reviews, box office collection updates and latest Hindi movie videos. Download free HD wallpapers of Bollywood celebrities and recent movies and much more on Bollywood Hungama.
    The Big Bull Full Movie
    Pushpa Full Movie

    ReplyDelete