Tuesday, August 3, 2010

Windows File System I/0

Write a program using windows navigational features of File System I/0 Namespace.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Csharp
{
    /// <summary>
    /// (a)Navigating Windows directories
    /// </summary>
    class Files
    {
        public static void Main(string[] args)
        {
            windows obj = new windows();
            obj.fileinfo();
            obj.dirinfo();
            obj.driveinfo();
            Console.ReadLine();
        }
    }
    class windows
    {
        public void fileinfo()
        {
            FileInfo fs = new FileInfo("C:\\Introduction to Csharp.ppt");
            Console.WriteLine("The files in C: \n");
            Console.WriteLine("File Name:\t{0}", fs.Name);
            Console.WriteLine("File Path:\t{0}", fs.FullName);
            Console.WriteLine("File LastAccessTime:\t{0}", fs.LastAccessTime);
            Console.WriteLine("File Last WriteTime:\t{0}", fs.LastWriteTime);
            Console.WriteLine("File CreationTime:\t{0}", fs.CreationTime);
         
        }
        public void dirinfo()
        {
            DirectoryInfo dir = new DirectoryInfo("C:\\");
            foreach (FileInfo fs in dir.GetFiles())
            {
                Console.WriteLine("{0}",fs.Name);
               
            }
            foreach (DirectoryInfo dr in dir.GetDirectories())
            {
                Console.WriteLine("{0}", dr.Name);
            }
        }
        public void driveinfo()
        {
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                Console.WriteLine("Drive: {0}", drive.Name);
                Console.WriteLine("Type: {0}", drive.DriveType);
            }
        }
    }
}

No comments:

Post a Comment