Get disk Capacity Method c#/c++

Source: Internet
Author: User

  • C # methods

    string drivename ="C:\ \";

    System. IO. DriveInfo[] drivers = System. IO. DriveInfo. Getdrives();

    foreach (var drive in drivers)

    {

    if (drivename = = Drive. Name)

    Console. WriteLine(drive. Totalfreespace /(1024x768 * 1024x768 *1.0F) + "G");

    }

    C # can only fetch all of the disks at once, so if you specify a disk, you need to judge and get the Space unit in bytes (byte)

  • C + + Methods

    DWORD64 qwfreebytes, qwfreebytestocaller, qwtotalbytes;

    Bresult =GetDiskFreeSpaceEx(TEXT("C:"),

    (pularge_integer) &Qwfreebytestocaller,

    (pularge_integer) &qwtotalbytes,

    (pularge_integer) &qwfreebytes);

    If (bresult)

    {

    cout <<"Use GetDiskFreeSpaceEx"<< Endl;

    cout <<"total Byte:"<< qwtotalbytes << Endl;

    cout <<"freebyte:"<< qwfreebytes << Endl;

    cout <<"Freebyte available:"<< qwfreebytestocaller << Endl ;

    cout <<"Free G"<< qwfreebytestocaller /1024x768/ 1024x768 / 1024x768 * 1.0F << Endl;

    }

    The GetDiskFreeSpaceEx function is explained on MSDN

    BOOL WINAPI GetDiskFreeSpaceEx (
    _in_opt_ LPCTSTR Lpdirectoryname,
    _out_opt_ Pularge_integer lpfreebytesavailable,
    _out_opt_ Pularge_integer Lptotalnumberofbytes,
    _out_opt_ Pularge_integer Lptotalnumberoffreebytes
    );

    GetDiskFreeSpaceEx gets the same data unit as Byte

Get disk Capacity Method c#/c++

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.