How to Get the Size of the Directory in VB.NET

How to Get the Size of the Directory in VB.NET thumbnail
VB.NET is available in Visual Studio and Visual Studio Express.

The .NET framework comes with a class library that provides access to Windows system functions. Developers instantiate classes and reference functions within the classes in their applications. This class library provides several benefits, such as faster development, easier reuse of code, increased scalability and easier deployment. The Directory class is one of the class libraries available in .NET that is used to access files and directories.

Instructions

  1. Using the Directory Class in .NET

    • 1

      Type "Imports System.IO" in the "declarations" section. This allows your program to access the Directory class functions.

    • 2

      Create a function that will perform the folder size computation. Name it something that appropriately describes what the function does. Pass the directory name to this function so that it knows where to look for the files to count. Declare variables within this function of type Long, FileInfo and DirectoryInfo.

    • 3

      Get the length of each file in the specified directory. Add the length of each file to the variable of type Long that will be used to store the total size of all files. The command used to get the length of a file is "FileInfo.Length."

    • 4

      Count all the files, including subdirectories, by calling "DirectoryInfo.GetDirectories" and then referencing this same function, passing the name of the subdirectory. This will force the function to call itself and get the length of each file in the particular subdirectory name. The total will be accumulated in that Long variable defined earlier that keeps a tally of the length of each file.

Related Searches:

References

  • Photo Credit Hemera Technologies/PhotoObjects.net/Getty Images

Comments

You May Also Like

  • How do I Make MP3 CDs on Shareaza?

    Shareaza is a file-sharing service that allows you to browse and search for media files and download them to your hard drive....

  • How to Zip Files Using VB Net

    Knowing how to zip files using Visual Basic.NET (VB.NET) can save you time if you need to compress a lot of files....

  • Long-Term Stay Hotels near Edmond, Okla.

    Long-Term Stay Hotels near Edmond, Okla.. Edmond, Okla., is an Oklahoma City suburb located along historic Route 66. Its pedestrian-friendly downtown district...

  • Definition of File Directory Folder

    A file directory or folder is a location in a computer where files are stored. Much like an office filing cabinet, an...

  • How to Create a Class File in .NET

    Classes provide applications with reusable, portable code. Classes are logical sections of an applications. For instance, the call to a database and...

  • How to Zip a File in VB.Net

    It can be useful to know how to compress files using Visual Basic.NET (VB.NET) if you often have to compress files manually....

  • How to Get a User Profile in VBS

    Windows stores information about the current user, basic system settings, and major directories in special variables known as environment variables. You can...

  • How to Change Font Color & Size

    When designing websites, the font size, by default, is 10 to 12 points. Most of the time, unless you are using a...

  • How to Calculate Average File Size

    Calculating an average file size allows a user to estimate an amount of disc space needed for storage and backup or an...

Related Ads

Featured