获取任意文件夹的大小.txt
来自「获取所要查讯文件夹所在磁盘剩余空间的大小」· 文本 代码 · 共 31 行
TXT
31 行
// floderNum.cpp : Defines the entry point for the console application.
//获取本地电脑上任意文件夹的大小,结果以MB为单位
#include <iostream>
#import "scrrun.dll" raw_interfaces_only
int main()
{
char *pathFloder = "c:\\data";
CoInitialize(NULL);
{
try
{
Scripting::IFileSystem3Ptr fs;
fs.CreateInstance(__uuidof(Scripting::FileSystemObject));
Scripting::IFolderPtr folder;
fs->GetFolder(_bstr_t(pathFloder),&folder);
_variant_t vsize;folder->get_Size(&vsize);
printf("%4.6fMB\n",(long)vsize/1024.0/1024.0);
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
std::cout<<"Get directory size via FileSystemObject, by masterz"<<std::endl;
std::cout<<"COM error occurred,source:"<<(LPCTSTR)bstrSource<<std::endl;
std::cout<<"Description:"<<(LPCTSTR)bstrDescription<<std::endl;
}
}
CoUninitialize();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?