Chinaunix首页 | 论坛 | 博客
  • 博客访问: 970909
  • 博文数量: 120
  • 博客积分: 6454
  • 博客等级: 准将
  • 技术积分: 1739
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-28 17:45
文章分类

全部博文(120)

文章存档

2014年(1)

2013年(1)

2012年(11)

2011年(16)

2010年(6)

2009年(11)

2008年(30)

2007年(44)

分类: C/C++

2008-08-03 11:11:39

 

/***********************************************/
/* check harddisk's free space and used space */
/**********************************************/
void checkDisk()
{
    char systemInfo[256];
    memset(systemInfo,0,256);
    _ULARGE_INTEGER lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
    DWORD serialNumber, maxComponentLength, fsFlags;
    TCHAR szFileSystem[12];
    TCHAR szVolumeName[24];
    TCHAR szRoot[4];
    
    DWORD AllDrives = GetLogicalDrives(); //#include

    if (AllDrives == 0)
        return ;
    
    char drive;
    int cnt = 0;
    for(int i=0; i<26; i++)
    {
        drive = i+'A';
        
        sprintf(szRoot,"%c:\\",drive);
        
        if(GetDriveType(szRoot) == DRIVE_FIXED)
        {
            cnt = cnt + 1;
            printf("\n%s\n",szRoot);
            if (!GetVolumeInformation(
                szRoot,
                szVolumeName,//卷标

                sizeof(szVolumeName),
                &serialNumber,//卷序列号

                &maxComponentLength,
                &fsFlags,
                szFileSystem,
                sizeof(szFileSystem)))
            {
                printf("Failed to retrieve drive information\n");
            }
            
            GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
            
            printf("卷标: %s\n分区类型: %s\n卷序列号: %04X-%04X\n",
                szVolumeName,
                szFileSystem,
                serialNumber >> 16,
                serialNumber & 0xFFFF
                );
            printf("分区总空间大小: %d MB\n",lpTotalNumberOfBytes.QuadPart / (1024 *1024));
            printf("分区剩余空间大小: %d MB\n",lpTotalNumberOfFreeBytes.QuadPart / (1024 *1024));
            printf("调用者可用的空间大小: %d MB\n",lpFreeBytesAvailableToCaller.QuadPart / (1024 *1024));
            sprintf(systemInfo, "%s\n%c:%dMB", systemInfo ,drive, lpFreeBytesAvailableToCaller.QuadPart / (1024 *1024));
        }
        else
            if (GetDriveType(szRoot) == DRIVE_CDROM)
            {
                printf("\nCD ROM:%s\n",szRoot);
            }
            else
                if (GetDriveType(szRoot) == DRIVE_REMOVABLE)
                {
                    printf("\nRemoveable ROM:%s\n",szRoot);
                }
    }
    printf("\n\n\n%s\n\n",systemInfo);
}

阅读(1813) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~