IT_Programming/C · C++

하드 디스크의 남은 용량 확인하는 API

JJun ™ 2007. 11. 22. 02:05
#include <windows.h>
#include <stdio.h> int main()
{
    int nDiskCheck;
    unsigned int nDiskType;
    char Drive[10];

    ULARGE_INTEGER m_lFreeBytesAvailableToCaller;
    ULARGE_INTEGER m_lTotalNumberOfBytes;
    ULARGE_INTEGER m_lTotalNumberOfFreeBytes;

    for (nDiskCheck='C' ; nDiskCheck <= 'Z' ; nDiskCheck++)
    {
        wsprintf(Drive, "%c:", nDiskCheck);
        nDiskType = GetDriveType(Drive);
        if (nDiskType == DRIVE_FIXED)   // HDD
        {
        int res =  GetDiskFreeSpaceEx( Drive,
            &m_lFreeBytesAvailableToCaller,
            &m_lTotalNumberOfBytes,
            &m_lTotalNumberOfFreeBytes );

        printf("****************************************n");
        printf("Disk Name => %sn", Drive);
        printf("Total Disk Space => %ldn", m_lTotalNumberOfBytes.QuadPart/1024);
        printf("Free Disk Space => %ldn", m_lTotalNumberOfFreeBytes.QuadPart/1024);
        printf("Using Disk Space => %ldn", ( (m_lTotalNumberOfBytes.QuadPart/1024) -(m_lTotalNumberOfFreeBytes.QuadPart/1024)));
        }
    }
    return 0;
}