
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to calculate the Size of Folder using C#?
To calculate the size of a folder in C#, use the Directory.EnumerateFiles Method and get the files.
To get the sub- directories, use the EnumerateDirectories method. Our folder is set using DirectoryInfo class −
DirectoryInfo info = new DirectoryInfo(@"D:/new");
Now find the size −
long totalSize = info.EnumerateFiles().Sum(file => file.Length);
For the directories, use −
info.EnumerateDirectories()
Other manipulations you can perform on Directories in C# are:
Method | Description |
---|---|
CreateDirectory(String) | Creates all directories and subdirectories in the specified path unless they already exist. |
CreateDirectory (String, DirectorySecurity) | Creates all the directories in the specified path, unless the already exist, applying the specified Windows security. |
Delete(String) | Deletes an empty directory from a specified path. |
Delete(String, Boolean) | Deletes the specified directory and, if indicated, any subdirectories and files in the directory. |
EnumerateDirectories(String) | Returns an enumerable collection of directory names in a specified path. |
- Related Articles
- How to calculate the size of folder using Java?
- How to get the folder size using PowerShell?
- How to calculate a directory size using Python?
- How to zip a folder recursively using Python?
- How to share a windows folder using PowerShell?
- How to remove windows folder sharing using PowerShell?
- How to get the directories (only) from a folder using Java?
- How to write files to the assets folder in android using Kotlin?
- How to delete folder and sub folders using Java?
- How to create a directory in project folder using Java?
- How to change SMB shared folder access permission using PowerShell?
- How to copy files from one folder to another using Python?
- How to change the size of the Console using PowerShell?
- How to calculate the length of the string using C#?
- What is Grounding Conductor and How to Calculate its Size?

Advertisements