windows下磁盘相关接口调用实例
1、windows下获取磁盘空间接口调用实例
//windows下获取磁盘空间接口调用
void GetDiskSpaceTest(void)
{
/*
qwFreeBytesToCaller:表示用户可用的剩余空间
qwTotalBytes:表示磁盘的总空间
qwFreeBytes:表示磁盘的剩余空间(磁盘可用空间)
*/
DWORD64 qwFreeBytes, qwFreeBytesToCaller, qwTotalBytes;
BOOL fResult;//返回0表示该函数调用出错
CString strOutPut;
fResult = GetDiskFreeSpaceEx(_T("D:"),
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if( !fResult ){
int nError = GetLastError();
strOutPut.Format(_T("Getlasterror:errorcode = %d\n"),nError);
OutputDebugString(strOutPut);
return;
//输出空间信息以MB为单位
strOutPut.Format(_T("Total:%I64u MB,Free:%I64u MB,Remain:%I64u MB\n"),
qwTotalBytes/1024/1024,qwFreeBytesToCaller/1024/1024,
qwFreeBytes/1024/1024);
OutputDebugString(strOutPut);
//输出空间信息以GB为单位
strOutPut.Format(_T("Total:%I64u GB,Free:%I64u GB,Remain:%I64u GB\n"),
qwFreeBytes/1024/1024/1024);
OutputDebugString(strOutPut);
}
以下是我的个人公众号,主要作为C/C++语言技术分享使用,该公众号里干货满满,如果您有对此博文的疑问或者java方面的问题也可以添加公众号交流讨论。最后,再次希望您能添加关注,互相交流互相学习共同进步:
MSDN GetDiskFreeSpaceEx 函数地址:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx