Question #38495




As part of her business activities, Sharon has created a large number of files and folders.
Whenever she needs to view the details of the files stored in a folder, Sharon browses to the folder
using Windows Explorer. However, she finds it cumbersome to browse to each individual folder to
view the desired details. Therefore, she asks Hayley to modify the application to accept the name
of a folder and display the following details of the files located in the folder:
File name
File size
File creation date
Write the code that Hayley should write to create the desired file information viewer application.

Expert's answer

class Program
{
    static void Main(string[] args)
    {
        string filePass = @"D:\"; //folder pass
        if (System.IO.Directory.Exists(filePass)) // Does folder exist?
        {
            string[] fileNames = System.IO.Directory.GetFiles(filePass); //getting names of files
            Console.WriteLine("Directory: {0} contains {1} file(s)", filePass, fileNames.Length);
            for (int i = 0; i < fileNames.Length; i++)
            {
                if (System.IO.File.Exists(fileNames[i]))
                {
                    long size = (System.IO.File.ReadAllBytes(fileNames[i])).Length; //file size
                    DateTime cr_date = System.IO.File.GetCreationTime(fileNames[i]); //creation date
                    string date = cr_date.Day + "." + cr_date.Month + "." + cr_date.Year;
                    Console.WriteLine("{0,30} \t{1,10} byte(s) \t{2}", fileNames[i], size, date);
                }
            }
        }
        else Console.Write("Pass doesn't exist");
        Console.ReadKey();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS