得到驱动器信息

得到驱动器信息

RFs 可以通过 Drive() 方法得到一个 TDriveInfo 的对像,该对像描述的驱动器信息

定义如下:TInt Drive(TDriveInfo& anInfo,TInt aDrive=KDefaultDrive) const

传入一个 TDriveInfo 对像,及一个 EDriveA~Z 的对像, DriveA~Z 表示驱动器,如果要遍例所有的驱动器

可以通过

TInt driverNumber =EDriveA;
 for (;driverNumber<=EDriveZ;driverNumber++)
 {
  ifs.Drive(di,driverNumber);
  if (di.iDriveAtt == KDriveAbsent)
   continue;
  
  }

TDriveInfo 有 iDriveAtt 属性表示驱动器属性,有以下值

Location: e32std.h 
 
Drive attributes
--------------------------------------------------------------------------------
KDriveAttLocal
const TUint KDriveAttLocal
Description
Drive is local.  本地驱动
--------------------------------------------------------------------------------
KDriveAttRom
const TUint KDriveAttRom
Description
ROM drive.       ROM 驱动
--------------------------------------------------------------------------------
KDriveAttRedirected
const TUint KDriveAttRedirected
Description
Output from a process on one drive redirected to another drive.
进程在一个驱动的输出重新定向到另外一个驱动上
--------------------------------------------------------------------------------
KDriveAttSubsted
const TUint KDriveAttSubsted
Description
Drive letter has been substituted (assigned a path).
驱动器被替代(指向一个路径)
--------------------------------------------------------------------------------
KDriveAttInternal
const TUint KDriveAttInternal
Description
Drive is internal (not removable).
--------------------------------------------------------------------------------
KDriveAttRemovable
const TUint KDriveAttRemovable
Description
Drive is removable.
 

其它的属性 iMediaAtt 及 iType和iBattery 可以查询 sdk

具体使用请看以下代码(来自 sdk例子)


#include  " DriveInfoLx.h "
#include 
< e32base.h >
#include 
< e32std.h >
#include 
< e32cons.h >              //  Console
#include  < f32file.h >

//   Constants
_LIT(KTextConsoleTitle,  " Console " );
_LIT(KTextFailed, 
"  failed, leave code = %d " );
_LIT(KTextPressAnyKey, 
"  [press any key]\n " );

//   Global Variables
LOCAL_D CConsoleBase *  console;   //  write all messages to this
RFs ifs;
//   Local Functions
void  formatDriveInfo(TDes &  abuf,TDriveInfo  & di);
void  printDriveInfo()
{
 User::LeaveIfError(ifs.Connect());
 TDriveInfo di;
 TBuf
< 256 >  buf;
 TInt driverNumber 
= EDriveA;
 
for  (;driverNumber <= EDriveZ;driverNumber ++ )
 {
  ifs.Drive(di,driverNumber);
  
if  (di.iDriveAtt  ==  KDriveAbsent)
   
continue ;
  
  formatDriveInfo(buf,di);
  buf.Delete(
0 ,buf.Length());
  console
-> Getch();
 }
 
 ifs.Close();
}
void  formatDriveInfo(TDes &  abuf,TDriveInfo  & di)
{
 _LIT(KFormatString,
" iType=%02x,iDriveAtt=%02x,iMediaAtt=%02x\n " );
 _LIT(KBatLow,
" Battery low\n " );
 _LIT(KBatgood,
" Battery good\n " );
 _LIT(KBatNotsupported,
" Battery not supported " );
 _LIT(KNotPresent,
" No media present\n " );
 _LIT(Kfloppy,
" Media is floppy disk\n " );
 _LIT(KHard,
" Media is hard disk\n " );
 _LIT(KCDROM,
" Media is CD-ROM\n " );
 _LIT(KRam,
" Media is RAM\n " );
 _LIT(KRom,
" Media is ROM\n " );
 _LIT(KFlash,
" Media is flash\n " );
 _LIT(KRemote,
" Media is remote\n " );
 _LIT(KUnknown,
" Media is unknown\n " );
 _LIT(KDriveAtts,
" Drive attributes: " );
 _LIT(KLocal,
"  local " );
 _LIT(KRomDrive,
"  Rom " );
 _LIT(KRedirected,
"  redirected " );
 _LIT(KSubstituted,
"  substituted " );
 _LIT(KInternal,
"  internal " );
 _LIT(KRemoveable,
"  removeable " );
 _LIT(KDynamic,
"  dynamic " );
 _LIT(KDual,
"  dual-desity " );
 _LIT(KFormattable,
"  formattable " );
 _LIT(KWriteProtected,
"  write-protected " );
 _LIT(KnewLine,
" \n " );
 _LIT(KMediaAtts,
" \nMedia attributes: " );
 abuf.AppendFormat(KFormatString,TInt(di.iType),TInt(di.iBattery),TInt(di.iDriveAtt)
  ,TInt(di.iMediaAtt));
 
switch (di.iBattery)
 {
 
case  EBatLow:
  abuf.Append(KBatLow);
  
break ;
 
case  EBatGood:
  abuf.Append(KBatgood);
  
break ;
 
default :
  abuf.Append(KBatNotsupported);
 }
 
switch (di.iType)
 {
 
case  EMediaNotPresent:
  abuf.Append(KNotPresent);
  
break ;
 
case  EMediaFloppy:
  abuf.Append(Kfloppy);
  
break ;
 
case  EMediaHardDisk:
  abuf.Append(KHard);
  
break ;
 
case  EMediaCdRom:
  abuf.Append(KCDROM);
  
break ;
 
case  EMediaRam:
  abuf.Append(KRam);
  
break ;
 
case  EMediaFlash:
  abuf.Append(KFlash);
  
break ;
 
case  EMediaRom:
  abuf.Append(KRom);
  
break ;
 
case  EMediaRemote:
  abuf.Append(KRemote);
  
break ;
 
default :
  abuf.Append(KUnknown);
 }
 
 abuf.Append(KDriveAtts);
 
if  (di.iDriveAtt  &&  KDriveAttLocal)
  abuf.Append(KLocal);
 
if  (di.iDriveAtt  &&  KDriveAttRom)
  abuf.Append(KRomDrive);
 
if  (di.iDriveAtt  &&  KDriveAttRedirected)
  abuf.Append(KRedirected);
 
if  (di.iDriveAtt  &&  KDriveAttSubsted)
  abuf.Append(KSubstituted);
 
if  (di.iDriveAtt  &&  KDriveAttInternal)
  abuf.Append(KInternal);
 
if  (di.iDriveAtt  &&  KDriveAttRemovable)
  abuf.Append(KRemoveable);
 abuf.Append(KMediaAtts);
 
if  (di.iMediaAtt  &&  KMediaAttVariableSize)
  abuf.Append(KDynamic);
 
if  (di.iMediaAtt  &&  KMediaAttDualDensity)
  abuf.Append(KDual);
 
if  (di.iMediaAtt  &&  KMediaAttFormattable)
  abuf.Append(KFormattable);
 
if  (di.iMediaAtt  &&  KMediaAttWriteProtected)
  abuf.Append(KWriteProtected);
 abuf.Append(KnewLine);
 console
-> Printf(abuf);
 
}
LOCAL_C 
void  MainL( const  TDesC &  aArgs)
    {
    
//
    
//  add your program code here, example code below
    
//
    
// console->Write(_L("Hello, world!\n"));
 printDriveInfo();
    console
-> Printf(_L( " Command line args: \ " % S\ " \n " ),  & aArgs);
    }

 

通过 TVolumeInfo 可以得到驱动器的总空间及剩余空间大小,及 DriveInfo 信息,同时也能得到 Drive Name  ,但代码里写上就是无法得到
VolumeName,不知是不是模拟器与真机不同,以下是测试代码

void  viewVolumnInfo()
{
    User::LeaveIfError(ifs.Connect());
    _LIT(KVInfo,
" drive:%S\nTotal size:%d\nFree Size:%d\n " );

    TVolumeInfo  vi;
    TInt driveNum
= EDriveA;
    
for  (;driveNum <= EDriveZ;driveNum ++ )
    {
        TInt error 
=  ifs.Volume(vi,driveNum);
        
if  (error  != KErrNone )
        {
            
            console
-> Printf(KVInfo, & vi.iName,vi.iSize,vi.iFree);
            console
-> Getch();
        }
        
    }

    ifs.Close();
}

 

你可能感兴趣的:(驱动)