Implementing Windows File System using VB.NET

In the article you will learn how to implement the Windows File System.
  • 1538

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:

7.gif


Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.