[C++] 纯文本查看 复制代码
BOOL WINAPI GetVolumeInformation(
__in_opt LPCTSTR lpRootPathName,
__out LPTSTR lpVolumeNameBuffer,
__in DWORD nVolumeNameSize,
__out_opt LPDWORD lpVolumeSerialNumber,
__out_opt LPDWORD lpMaximumComponentLength,
__out_opt LPDWORD lpFileSystemFlags,
__out LPTSTR lpFileSystemNameBuffer,
__in DWORD nFileSystemNameSize
);
[C++] 纯文本查看 复制代码
#include "stdafx.h"
#define MaxLength 1024
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "chs"); //为了下面打印能正常显式中文,进行了本地化设置
TCHAR VolumeNameBuffer[MAX_PATH];
DWORD VolumeSerialNumber;
DWORD MaximumComponentLength;
DWORD FileSystemFlags;
TCHAR FileSystemNameBuffer[MaxLength];
TCHAR Buffer[MaxLength];
GetLogicalDriveStrings(MaxLength, Buffer);
PTSTR Device = (PTSTR)Buffer;
do {
if ( !GetVolumeInformation(
Device,
VolumeNameBuffer,
MAX_PATH,
&VolumeSerialNumber,
&MaximumComponentLength,
&FileSystemFlags,
FileSystemNameBuffer,
MaxLength
)
) {
return FALSE;
}
_tprintf (TEXT("%s\n"),Device);
_tprintf (TEXT("磁盘驱动器卷标名称:%s\n"), VolumeNameBuffer);
_tprintf (TEXT("磁盘驱动器卷标序列号: %u\n"), VolumeSerialNumber);
_tprintf (TEXT("系统允许最大文件名长度:%u\n"), MaximumComponentLength);
_tprintf (TEXT("文件系统类型:%s\n"), FileSystemNameBuffer);
if (FileSystemFlags & FILE_CASE_PRESERVED_NAMES)
_tprintf (TEXT("The specified volume supports preserved case of file names when it places a name on disk.\n"));
if (FileSystemFlags & FILE_CASE_SENSITIVE_SEARCH)
_tprintf (TEXT("The specified volume supports case-sensitive file names.\n"));
if (FileSystemFlags & FILE_FILE_COMPRESSION)
_tprintf (TEXT("The specified volume supports file-based compression.\n"));
if (FileSystemFlags & FILE_NAMED_STREAMS)
_tprintf (TEXT("The specified volume supports named streams.\n"));
if (FileSystemFlags & FILE_VOLUME_QUOTAS)
_tprintf (TEXT("The specified volume supports disk quotas.\n"));
_tprintf (TEXT("------------------------------------------------------------------\n"));
Device += (lstrlen((LPCWSTR)Device) + 1);
} while (*Device);
return 0;
}