遍历卷,遍历磁盘

#include<windows.h>
#include<stdio.h>
#include<stdlib.h>

#define BUFF 1024

int main()
{
    CHAR szLogicalDrierStrings[BUFF];
    ZeroMemory(szLogicalDrierStrings,BUFF);
    GetLogicalDriveStrings(BUFF, szLogicalDrierStrings);

    PCHAR pLogical = NULL;
    pLogical = (PCHAR)szLogicalDrierStrings;
    //C:\\0D:\\0......
    do 
    {
        printf("%s\n", pLogical);
        pLogical += (lstrlen(szLogicalDrierStrings) + 1);
    } while (*pLogical != '\0');
    

    TCHAR buf[BUFF];
    HANDLE hVol;

    hVol = FindFirstVolume(buf, BUFF);
    if (hVol == INVALID_HANDLE_VALUE)
    {
        printf("Error = %d\n", GetLastError());
        system("pause");
        return 0;
    }

    printf("%s\n", buf); //设备名称

    while (FindNextVolume(hVol, buf, BUFF))
    {
        printf("%s\n", buf); //设备名称
    }

    FindVolumeClose(hVol);

    /*
        C: \
        D : \
        E : \
        F : \
        //设备名称
        \\ ? \Volume{ 9757d529 - 3b7d - 11e7 - 9673 - 806e6f6e6963 }\
        \\ ? \Volume{ 9757d52a - 3b7d - 11e7 - 9673 - 806e6f6e6963 }\
        \\ ? \Volume{ 9757d52b - 3b7d - 11e7 - 9673 - 806e6f6e6963 }\
        \\ ? \Volume{ 9757d530 - 3b7d - 11e7 - 9673 - 806e6f6e6963 }\
    */
    system("pause");
    return 0;
}

 

posted @ 2017-05-21 15:16  DeeLMind  阅读(377)  评论(0编辑  收藏  举报