#import "scrrun.dll" raw_interfaces_only
// 参数格式:"c:\" 或 "c:\test"
ULONGLONG GetPathUseSpace(const char *szPath)
{
ASSERT(szPath != NULL);
int nLen = strlen(szPath);
if (nLen == 0)
return 0;
ULONGLONG result = 0;
if (nLen == 3) // c:\
{
ULARGE_INTEGER nFreeBytesAvailable;
ULARGE_INTEGER nTotalNumberOfBytes;
ULARGE_INTEGER nTotalNumberOfFreeBytes;
//
if (GetDiskFreeSpaceEx(szPath,
&nFreeBytesAvailable,
&nTotalNumberOfBytes,
&nTotalNumberOfFreeBytes))
{
result = nTotalNumberOfBytes.QuadPart - nFreeBytesAvailable.QuadPart;
}
}
else
{
CoInitialize(NULL);
{
try
{
Scripting::IFileSystem3Ptr fs;
fs.CreateInstance(__uuidof(Scripting::FileSystemObject));
Scripting::IFolderPtr folder;
fs->GetFolder(_bstr_t(szPath),&folder);
_variant_t vsize;
folder->get_Size(&vsize);
result = (double)vsize;
}
catch(_com_error &e)
{
result = -1;
}
}
CoUninitialize();
}
return result;
}
VC取得目录的大小可以用COM方式,但是在某些操作系统上使用COM方式取根目录大小(即某一个盘已用空间)会出现问题,可以用GetDiskFreeSpaceEx,上面是我写了一个小函数。
posted on 2008-07-02 16:33
胡满超 阅读(2902)
评论(13) 编辑 收藏 引用