わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。

ボリューム名一覧を取得する

ボリューム名一覧を取得します。ボリューム名の列挙の為には、FindFirstVolume()関数 、FindNextVolume()関数、FindClose()関数を利用します。ファイルを列挙する時のFindFirstFile()関数 などと同じ要領で使用します。

ボリューム名一覧を取得する
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <windows.h>
 
 
 
/*
    ボリューム名一覧を取得する
*/
int _tmain
(
      int argc
    , _TCHAR* argv[]
)
{
    // 標準出力にユニコード出力する
    setlocale( LC_ALL, "Japanese" );
 
    TCHAR waBuffer[ MAX_PATH ];
 
    HANDLE hFind = INVALID_HANDLE_VALUE;
 
    // 最初に一致するボリュームの取得
    hFind = FindFirstVolume(
              waBuffer
            , _countof( waBuffer )
        );
    if ( INVALID_HANDLE_VALUE != hFind ) {
 
        do {
         
            // ボリュームの表示
            wprintf( L"%s¥n", waBuffer );
 
        // 次に一致するボリュームの取得
        } while( 0 != ::FindNextVolume( hFind, waBuffer, _countof( waBuffer ) ) );
 
        // ボリュームのクローズ
        ::FindVolumeClose( hFind );
    }
 
    // 正常終了
    return( 0 );
}

実行結果

\\?\Volume{6e367b81-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{fdc0794c-e8e0-11df-a2b4-002215764f77}\
\\?\Volume{a16fd905-b956-11df-916f-806e6f6e6963}\
\\?\Volume{f0e4b3a5-911c-11df-bff8-806e6f6e6963}\
\\?\Volume{0dde29a5-19e0-11e2-9171-005056c00008}\
\\?\Volume{6e367b82-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{f41f2e6d-6746-11e2-9fef-806e6f6e6963}\
\\?\Volume{f41f2e6e-6746-11e2-9fef-806e6f6e6963}\
\\?\Volume{6e367b9b-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{6e367b9c-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{6e367b9d-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{6e367b9e-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{6e367b9f-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{6e367b87-881f-11df-bc12-806e6f6e6963}\
\\?\Volume{6e367b86-881f-11df-bc12-806e6f6e6963}\






わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。