Get Drive Information

Source: Internet
Author: User

Get Drive Information

RFs can get a TDriveInfo object through the Drive () method, and the Drive information of the Object Description

Definition: TInt Drive (TDriveInfo & anInfo, TInt aDrive = KDefaultDrive) const

Input a TDriveInfo object and an EDriveA ~ Z's image, DriveA ~ Z indicates the drive, if you want to repeat all the drives

You can use

TInt driverNumber = EDriveA;
For (; driverNumber <= EDriveZ; driverNumber ++)
{
Ifs. Drive (di, driverNumber );
If (di. iDriveAtt = KDriveAbsent)
Continue;

}

TDriveInfo has the iDriveAtt attribute, which indicates the drive property and has the following values:

Location: e32std. h

Drive attributes --------------------------------------------------------------------------------
KDriveAttLocal
Const TUint KDriveAttLocal
Description
Drive is local. local driver
--------------------------------------------------------------------------------
KDriveAttRom
Const TUint KDriveAttRom
Description
ROM drive. ROM driver
--------------------------------------------------------------------------------
KDriveAttRedirected
Const TUint KDriveAttRedirected
Description
Output from a process on one drive redirected to another drive. The process redirects the Output of one driver to another.
--------------------------------------------------------------------------------
KDriveAttSubsted
Const TUint KDriveAttSubsted
Description
Drive letter has been substituted (assigned a path). Drive replaced (pointing to a path)
--------------------------------------------------------------------------------
KDriveAttInternal
Const TUint KDriveAttInternal
Description
Drive is internal (not removable ).
--------------------------------------------------------------------------------
KDriveAttRemovable
Const TUint KDriveAttRemovable
Description
Drive is removable.

Other attributes iMediaAtt, iType, and iBattery can be used to query the sdk.

For more information, see the following code (from the sdk example)

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

// Constants
_ Partition (KTextConsoleTitle, "Console ");
_ Blank (KTextFailed, "failed, leave code = % d ");
_ Keys (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)
{
_ Partition (KFormatString, "iType = % 02x, iDriveAtt = % 02x, iMediaAtt = % 02x \ n ");
_ Partition (KBatLow, "Battery low \ n ");
_ Partition (KBatgood, "Battery good \ n ");
_ Partition (KBatNotsupported, "Battery not supported ");
_ Representation (KNotPresent, "No media present \ n ");
_ Snapshot (Kfloppy, "Media is floppy disk \ n ");
_ Partition (KHard, "Media is hard disk \ n ");
_ Weight (KCDROM, "Media is CD-ROM \ n ");
_ Queue (KRam, "Media is RAM \ n ");
_ Weight (KRom, "Media is ROM \ n ");
_ Seek (KFlash, "Media is flash \ n ");
_ Metadata (KRemote, "Media is remote \ n ");
_ Unknown (KUnknown, "Media is unknown \ n ");
_ Attributes (KDriveAtts, "Drive attributes :");
_ Partition (KLocal, "local ");
_ Category (KRomDrive, "Rom ");
_ Commit (KRedirected, "redirected ");
_ Partition (KSubstituted, "substituted ");
_ Partition (KInternal, "internal ");
_ Removeable (KRemoveable, "removeable ");
_ Partition (KDynamic, "dynamic ");
_ Partition (KDual, "dual-desity ");
_ Partition (KFormattable, "formattable ");
_ Partition (KWriteProtected, "write-protected ");
_ Partition (KnewLine, "\ n ");
_ Attributes (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 );
}

 

You can use TVolumeInfo to obtain the total space and remaining space of the Drive, DriveInfo information, and Drive Name. However, you cannot obtain the Drive Name in the code.
VolumeName. I wonder if the simulator is different from the real machine. The following is the test code.

Void viewVolumnInfo ()
{
User: LeaveIfError (ifs. Connect ());
_ Partition (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 ();
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.