Q:

C# program to get the list of files from given directory

0

C# program to get the list of files from given directory

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string[] files;

            files =Directory.GetFiles("E:/pics/birthday-2014/");

            Console.WriteLine("File Names:");
            for (int i = 0; i < files.Length; i++)
            {
                Console.WriteLine("\t"+files[i]);
            }
        }
    }
}

Output

File Names:
        E:/pics/birthday-2014/IMG_20140814_212013.jpg
        E:/pics/birthday-2014/IMG_20140814_212204.jpg
        E:/pics/birthday-2014/IMG_20140814_212211.jpg
        E:/pics/birthday-2014/IMG_20140814_212219.jpg
        E:/pics/birthday-2014/IMG_20140814_212225.jpg
        E:/pics/birthday-2014/IMG_20140814_212229.jpg
        E:/pics/birthday-2014/IMG_20140814_212232.jpg

Note: In above program, we need to remember, when we use "Directory" class, System.IO namespace must be included in the program.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# file handling (File class) solved programs/examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the use of CreateSubdire... >>
<< C# program to get root directory of given director...