Home >Backend Development >C#.Net Tutorial >Find available disk space using C#

Find available disk space using C#

WBOY
WBOYforward
2023-09-06 10:29:021025browse

使用 C# 查找可用磁盘空间

First, create an instance of DriveInfo-

DriveInfo dInfo = new DriveInfo("E");

Display available space-

Console.WriteLine("Disk Free space = {0}", dInfo.AvailableFreeSpace);

Now, use the AvailableFreeSpace property and get the percentage of free space-

Double pc = (dInfo.AvailableFreeSpace / (float)dInfo.TotalSize) * 100;

Here you will get the percentage of free size to total disk space -

Console.WriteLine(" Free space (percentage) = {0:0.00}%.", pc);

The above is the detailed content of Find available disk space using C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:C# truncation methodNext article:C# truncation method