Start New Discussion within our Software Development Community

If you ever want to get information about files stored in a particular map or directory, you can find out how it is done here. With a little modification you could turn this snippet into a DOS DIR-command or a UNIX(LINUX?) ls-command.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;    //for file functions

namespace DirCommand
{
    class Program
    {
        static void Main(string[] args)
        {
            // get info for the c: directory or specify another
            //
            DirectoryInfo dirInfo = new DirectoryInfo(@"c:\");
            FileInfo[] files = dirInfo.GetFiles();  // get a list of fileInfo

            // dump it to the console
            Console.WriteLine("Name:\t\tSize:\t\tCreation date:");
            foreach (FileInfo file in files)
            {
                Console.Write(file.Name.PadRight(16));
                Console.Write(file.Length.ToString().PadRight(16));
                Console.WriteLine("\t" + file.CreationTime.ToString());
                // add any method of FileInfo you like here
            }
            Console.ReadKey();
        }
    }
}
The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.