获取可用的驱动器及其大小的列表 [英] Get a list of the available drives and their sizes
问题描述
我知道你可以使用GetLogicalDrives()和GetDiskFreeSpaceEx()的组合来获取驱动器及其大小的列表。我一直在使用GetDiskFreeSpaceEx(),没有问题,但是当我尝试使用GetLogicalDrives()我遇到了一个问题:我不希望有检查每一个可能的字母,看看它是否存在与否它传递给GetDiskFreeSpaceEx前()
I know you can use a combination of GetLogicalDrives() and GetDiskFreeSpaceEx() to get the list of drives and their sizes. I've been using GetDiskFreeSpaceEx() with no problem but when I try to use GetLogicalDrives() I ran into a problem: I don't want to have to check each possible letter to see whether it exists or not before passing it to GetDiskFreeSpaceEx().
有没有一种简单的方法来获得系统的驱动器(硬盘)的名单,以及他们的大小?我使用C,在Windows上。
Is there a simpler way to get the list of drives (disk) on the system and what their sizes are? I am using C, on Windows.
我想做出点清楚,我的了解可能使用C#和WMI更容易,我对那个没兴趣,所以请不要张贴,作为一个可能的解决方案。如果你想指向C和WMI是如何做的,去了。没有C ++或C#的感谢! (就像有人在<一做href=\"http://stackoverflow.com/questions/2238606/how-to-check-whether-windows-file-indexing-is-on-or-off\">my previous问题)
I want to make something clear, I KNOW it might be easier using C# and WMI, I have no interest on that so please do not post that as a possible solution. If you want to point to how is done in C and WMI, go for it. NO C++ or C# thanks! (like someone did in my previous question)
推荐答案
GetLogicalDrives()是该系统提供的API。一个简单的for()循环将其结果转化为驱动器盘符,如:
GetLogicalDrives() is the system-provided API for that. A simple for() loop will translate its result into drive letters, like this:
DWORD d = GetLogicalDrives();
int i;
TCHAR Drive[] = _T("A:\\");
for(i=0;i<26;i++)
{
if(d & (1<<i))
{
Drive[0] = _T('A')+i;
GetDiskFreeSpaceEx(Drive, .....);
}
}
如果你是不是满意的服务,堆栈溢出提供,随意问你的钱要回来。水平
And if you're not satisfied with the level of service that Stack Overflow provides, feel free to ask for your money back.
这篇关于获取可用的驱动器及其大小的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!