×
Namespaces

Variants
Actions

如何获取磁盘空间大小

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
翻译:
hoolee
最后由 hamishwillee 在 22 Dec 2011 编辑

头文件:

#include <f32file.h>

链接库:

LIBRARY efsrv.lib

所需能力:

CAPABILITY NONE


#include <e32base.h>
 
class ClassName
{
public:
static TInt GetDriveSizeInfoL(TChar aDriveChar, TInt64& aDriveTotalSize, TInt64& aDriveFreeSize);
};


#include <f32file.h>
 
TInt ClassName :: GetDriveSizeInfoL(TChar aDriveChar, TInt64& aDriveTotalSize, TInt64& aDriveFreeSize)
{
TInt err = KErrNone;
 
aDriveTotalSize = 0;
aDriveFreeSize = 0;
 
RFs fs;
User::LeaveIfError( fs.Connect() );
 
TInt driveIndex;
err = RFs :: CharToDrive( aDriveChar, driveIndex );
if(err == KErrNone)
{
TDriveInfo driveInfo;
err = fs.Drive( driveInfo, driveIndex );
if(err == KErrNone)
{
if(driveInfo.iMediaAtt & KMediaAttFormattable) // size defined only for formattable drives
{
TVolumeInfo volumeInfo;
err = fs.Volume(volumeInfo, driveIndex);
if(err == KErrNone)
{
// now we can get drive size info
aDriveTotalSize = volumeInfo.iSize;
aDriveFreeSize = volumeInfo.iFree;
}
}
else
err = KErrArgument;
}
else
err = KErrArgument;
}
fs.Close();
 
return err;
}


如何使用:

TInt64 size, freeSize;
if(ClassName::GetDriveSizeInfoL('C', size, freeSize)==KErrNone)
{
....
}
This page was last modified on 22 December 2011, at 07:44.
78 page views in the last 30 days.
×