473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to measure hard disk capacity?

How to measure hard disk capacity?

Nov 16 '05 #1
2 12319
AlirezaH,

I would perform a WMI query for the instance of Win32_PhysicalMedia that
represents the actual drive and then check the Capacity property on it. You
can use the classes in the System.Management namespace to access this data.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"AlirezaH" <al******@abcgrp.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
How to measure hard disk capacity?

Nov 16 '05 #2
AlirezaH wrote:
How to measure hard disk capacity?


This will do a little more:

using System;
using System.Management;

namespace sample {

/// <summary>
/// Displays disk space information for all connected hard drives.
/// </summary>
class freeSpace {

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main() {
string query = "select name, FreeSpace, Size from win32_logicaldisk
where drivetype=3";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach(ManagementObject manobj in searcher.Get()) {
double freespace2 = double.Parse(manobj["FreeSpace"].ToString());
double disksize2 = double.Parse(manobj["Size"].ToString());
double pctfree2 = freespace2 / disksize2;
int lengthdiff = disksize2.ToString("N0").Length -
freespace2.ToString("N0").Length;

Console.WriteLine("For drive {0}", manobj["name"]);
Console.WriteLine("\tDisk size: " + disksize2.ToString("N0") + "
bytes");

/// <summary>
/// Format the free space line so the number lines up
/// right-justified with the disk size number
/// when using a fixed-width font.
/// </summary>
switch (lengthdiff) {
case 0:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0") +
" bytes");
break;
case 1:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0") +
" bytes");
break;
case 2:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0")
+ " bytes");
break;
case 3:
Console.WriteLine("\tFree space: " + freespace2.ToString("N0")
+ " bytes");
break;
default :
Console.WriteLine("\tFree space: " + freespace2.ToString("N0") +
" bytes");
break;
}
Console.WriteLine();

Console.WriteLine("\tPercent free: " + pctfree2.ToString("P"));
Console.WriteLine();
Console.WriteLine();
}
}
}
}
--
Take care,
Ken
(to reply directly, remove the cool car. <sigh>)
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hi: I am totally new in Sun Solaris. I am not sure someone would like to tell me how to rellocate Sun Solaris disk space where oracle installed? I installed Oracle 8i in Sun Solaris and set...
5
by: Ben Jeurissen | last post by:
Hello, I have to deal with the following issue in C++: Two threads are started from the main thread, both capturing images from a different firewire camera. Both threads take shots of 460800...
2
by: Joe | last post by:
Hi Guys, Is it possible to create a disk management system using .NET entirely. What I mean by the above is having an application possibly a .NET windows service monitoring the disk, creating...
3
by: abeer el ashker | last post by:
how can i get serial numper of hard disk using api
13
by: Shane Wright | last post by:
Hi, I've been trying to spec a new server for my company's database for a few weeks and one of the biggest problems I've had is trying to find meaningful performance information about how...
6
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk...
3
by: ary | last post by:
I try to create a weblog host site! in this case i can't use cache for every page because that cause to be my Server ram full of caching page. but if I can save cache in hard disk my problem...
2
by: =?Utf-8?B?R2VvcmR5?= | last post by:
Hello everyone, I would really appreciate if someone helped me in this matter cause I am going to lose my mind... I am using a Sony Vaio Laptop with Windows XP professional (512MB Ram, 1,7 GHz CPU...
10
by: kevinliu23 | last post by:
HI, I am new to Python and wanted to know how to check for the remaining disk space on my Windows machine using Python? I was thinking of using the command line "dir" and trying to extract the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.