ARTICLE

Implementing the Windows File System.

Posted by Sapna Articles | Visual Basic Language July 06, 2010
In the article you will learn how to implement the Windows File System.
 
Reader Level:


The ability to browse and locate files and directories for a specific directory is essential for many  programming tasks. You can work with files and directories by using classes such as the DirectoryInfo and FileInfo classes in combination. Using theses classes is an efficient way to gather the required information about files and directories in a specific location.

The DirectoryInfo class and FileInfo class are both derived from the FileSystemInfo class.

The following code shows the use of the FileInfo class:

using System;
using System.IO;
namespace File_Handling
{
    class Tester
    {
    public static void Main()
        {
            //creating an instance of DirectoryInfo class
            DirectoryInfo MydirInfo = new
            DirectoryInfo(@"c:\WINDOWS"); 
            //get all the files in the directory and print their name, and size
            FileInfo[] FileInDir = MydirInfo.GetFiles ();
            foreach (FileInfo file in FileInDir)
            {
               Console.WriteLine("File Name:{0}   size:{1} bytes",
                file.Name, file.Length);
            }
        }
    }
}

In the preceding code, the Getfiles() method is used to retrive the list of all the files in the directory. This displays the list of all the directories of the given location and their sizes like that:

WSE.gif

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor