Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



Location: bautils.h
Link against: bafl.lib

Class BaflUtils

class BaflUtils;

Description

Provides simple-to-use file system utilities.

The functions listed in "Copying, renaming, and deleting files" create and use a CFileMan object. They are useful for one-off calls, but for repeated use it is more efficient to use CFileMan directly.

Note that there is a very similiar group of functions available in EikFileUtils, which may be easier to use in GUI applications, as they do not require a file server session to be passed.

Members

Defined in BaflUtils:
AbbreviateFileName(), CheckFolder(), CheckWhetherFullNameRefersToFolder(), CopyFile(), CopyWithTruncation(), DeleteFile(), DiskIsReadOnly(), DriveAndPathFromFullName(), DriveIsReadOnlyInternal(), EnsurePathExistsL(), ExtractAppNameFromFullName(), FileExists(), FolderExists(), FolderNameFromFullName(), GetDiskListL(), GetDowngradePathL(), GetSystemDrive(), InitialiseHAL(), InitialiseLocale(), InitialiseScreenCalibration(), IsFirstDriveForSocket(), IsFolder(), MostSignificantPartOfFullName(), NearestLanguageFile(), NearestLanguageFile(), Parse(), PathExists(), PersistHAL(), PersistLocale(), PersistScreenCalibration(), RemoveSystemDirectory(), RenameFile(), RootFolderPath(), SortByTable(), UidTypeMatches(), UpdateDiskListL(), ValidateFolderNameTypedByUserL()

See also:


Member functions


CopyWithTruncation()

static IMPORT_C void CopyWithTruncation(TDes &aDest, const TDesC &aSrc, TChar aTruncationSymbol=KBaflCharTruncation);

Description

Copies a descriptor, abbreviating it to fit the destination descriptor.

If aSrc is less than the maximum length of aDest, then the string is simply copied to aDest.

If this is not so, then the left-most characters of aSrc are copied to aDest, up to aDest's maximum length-1. aDest's final character is set to be aTruncationSymbol.

Parameters

TDes &aDest

On return, the truncated string

const TDesC &aSrc

The string to truncate

TChar aTruncationSymbol

The truncation character to add


FileExists()

static IMPORT_C TBool FileExists(const RFs &aFs, const TDesC &aFileName);

Description

Checks if the specified file exists.

Parameters

const RFs &aFs

File server session

const TDesC &aFileName

File to check

Return value

TBool

ETrue if the file exists, otherwise EFalse


EnsurePathExistsL()

static IMPORT_C void EnsurePathExistsL(RFs &aFs, const TDesC &aFileName);

Description

Makes one or more directories, if they do not already exist.

Any valid path component in the specified path that does not already exist is created as a directory. If the specified path already exists, the function returns normally.

Parameters

RFs &aFs

File server session

const TDesC &aFileName

Path to ensure exists

See also:


ExtractAppNameFromFullName()

static IMPORT_C TPtrC ExtractAppNameFromFullName(const TFullName &aName);

Description

Gets the application name from a full thread name.

Parameters

const TFullName &aName

Thread name

Return value

TPtrC

Application name

See also:


NearestLanguageFile()

static IMPORT_C void NearestLanguageFile(const RFs &aFs, TFileName &aName);

Description

Searches for the file with the correct language extension for the language of the current locale, or failing this, the best matching file.

Parameters

const RFs &aFs

File server session.

TFileName &aName

File name as it would be without a language-specific extension. On return, this is changed to the language-specific version. If no such file is found, the name is unchanged.


NearestLanguageFile()

static IMPORT_C void NearestLanguageFile(const RFs &aFs, TFileName &aName, TLanguage &aLanguage);

Description

Set most appropriate extension language code for filename and set corresponding language.

Symbian uses numeric values to identify natural languages as specified by the TLanguage enumeration defined in e32const.h. These values are used at the end of filename extensions to identify the languages pertaining to files which have language specific variants such as resource files. For instance filename.r01 and filename.r02 would be the English and French versions of the resource file filename.rsc. Language codes can be between 2 to 5 digits in length.

Starting from Symbian OS v7.0 this function constructs and uses a language downgrade path which consists of up to sixteen TLanguage values the first of which is the ideal language followed by the language of the current locale. Up to the next three can be customised using TLocale::SetLanguageDowngrade(). The rest of the language downgrade path is based on a table of language near equivalence which is internal to Symbian.

This function searches the custom resource drive (if set, retrieved from HAL) and then searches the optional drive specified in aName or 'Z:' if none is specified in aName. The custom resource drive is retrieved from the HAL attribute ECustomResourceDrive if set, if not set it will retrieve the legacy value set in the legacy HAL attribute ESystemDrive. No custom resource drive is searched if neither are set. Note - setting the custom resource drive will reduce the performance of this routine which will adversely affect device performance e.g. at boot up. On NAND Flash based devices use of a composite Z: drive file system made up of multiple ROM images is the preferred mechanism for customising language resources on devices in Symbian OS 9.2 onwards, see Developer Library » Base Porting Guide » Porting: background information » NAND flash » NAND Flash image format. Thus use of the custom resource drive HAL attribute is effectively obsolete.

The last two characters of aName are removed along with any digits which appear before them. Then language codes specified in the constructed language downgrade path are appended in turn to aName as a match is searched for in the file system. In case no match is found using the constructed language downgradepath then files in the specified directory are searched for a suitable extension with preference given to the one specified if present. In cases where a match takes place the aName and aLanguage arguments are updated otherwise aName is left unchanged and aLanguage is set to ELangNone.

Here are some examples of correct and incorrect function usage with different aName inputs, file system state and downgrade paths as follows:

Following files exist:
C:\\abc.rsc  - Language Neutral resource file.
C:\\abc.r01  - Resource file for the English language.
C:\\abc.r10  - Resource file for the American-English language.
C:\\abc.r160 - Resource file for the English as appropriate in Japan.

Constructed Downgrade Language Path cases:
- Case 1. (ELangAmerican -> ELangEnglish -> ELangNone).
- Case 2. (ELangEnglish_Japan -> ELangEnglish -> ELangNone).
- Case 3. Same as case 1, However "C:\\abc.r10" is deleted prior to the function call.
- Case 4. Same as case 1, However both "C:\\abc.r01" and "C:\\abc.r10" are deleted prior to the function call.

Input aName . . . . Output aName. . . aLanguage . . . . . Description
--------------------------------------------------------------------------------------------------------------------
"C:\\abc.rsc" . . . "C:\\abc.r10" . . ELangAmerican . . . Match on first language (Case 1)
"C:\\abc.r10" . . . "C:\\abc.r10" . . ELangAmerican . . . Match, However it's not the intended use of 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . the function (Case 1)
"C:\\abc.r" . . . . "C:\\abc.r" . . . ELangNone . . . . . The no. of characters in the suffix is less than 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . KInvNameAndMinSuffixLength(2)(Case 1)
"C:\\abc.". . . . . "C:\\abc.". . . . ELangNone . . . . . Invalid Suffix: The filename ends with a period(Case 1)
"C:\\abc.r123456" . "C:\\abc.r123456" ELangNone . . . . . Invalid Suffix: The no. of digits in the suffix is greater 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . than KMaxSuffixLength(5) (Case 1)
"C:\\abc.10". . . . "C:\\abc.10 . . . ELangNone . . . . . Invalid Suffix: There's no proceeding alphabetical 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . characters in the suffix (Case 1)
"\\abc.rsc" . . . . "\\abc.rsc" . . . ELangNone . . . . . No drive so Z: search, no match (Case 1)
"C:\\abc.rsc" . . . "C:\\abc.r160". . ELangEnglish_Japan. Match for language file 3 digits long (Case 2)
"C:\\abc.rsc" . . . "C:\\abc.r01" . . ELangEnglish. . . . Match on second language (Case 3)
"C:\\abc.rsc" . . . "C:\\abc.rsc" . . ELangNone . . . . . No corresponding langauge file match found (Case 4)
---------------------------------------------------------------------------------------------------------------------

Parameters

const RFs &aFs

File server session.

TFileName &aName

Optional drive specification, followed by optional path name, followed by basename for filename, followed by period and extension. On return, in case of a match, this is replaced by the language-specific version which consists of the last two characters of the extension plus any preceding numeric characters being replaced by the language code. Remains unchanged when there's no match

TLanguage &aLanguage

On return, in case of a match, this is replaced by the corresponding language. In case of no match it's set to ELangNone.

See also:


GetSystemDrive()

static IMPORT_C TInt GetSystemDrive(TDriveNumber &aDriveNumber);

Description

Get the value of the system drive.

The system drive can be set to one of the built-in read/write drives. Which drive is used is hardware-dependent. On some hardware, there may not be a system drive. The system drive is used as the drive on which localisable files are searched for. This enables a phone to be localised dynamically, using files not in the ROM.

Parameters

TDriveNumber &aDriveNumber

On return, contains the drive number of the system drive.

Return value

TInt

KErrNone is always returned.


PathExists()

static IMPORT_C TBool PathExists(RFs &aFs, const TDesC &aFileName);

Description

Tests whether a path exists.

The path should contain a drive letter and a directory, or EFalse is returned. EFalse is also returned if it contains a filename or filename extension.

If the path is badly formed, for instance if it contains illegal characters, or any directory name consists of a single or double dot, or any directory name includes wildcard characters, the function returns EFalse.

Parameters

RFs &aFs

A connected session with the file server.

const TDesC &aFileName

The path to test for. It should end in a backslash.

Return value

TBool

ETrue if the path exists, EFalse if not. EFalse is also returned if the specified path is badly formed.


IsFolder()

static IMPORT_C TInt IsFolder(const RFs &aFs, const TDesC &aFullName, TBool &aIsFolder);

Description

Checks if the specified item is a folder.

Parameters

const RFs &aFs

File server session

const TDesC &aFullName

Name to check

TBool &aIsFolder

ETrue if aFullName is a folder, otherwise EFalse

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes


FolderExists()

static IMPORT_C TBool FolderExists(RFs &aFs, const TDesC &aFolderName);

Description

Tests whether a folder exists.

The folder is specified in a path. The path can omit the drive letter, in which case the drive letter is taken from the session path.

If the path is badly formed, for instance if it contains illegal characters, or any directory name consists of a single or double dot, or any directory name includes wildcard characters, the function returns EFalse.

If a filename is included in the path, it is ignored (the existence of the file will not be checked). However if included, it must not be badly formed - this will cause the function to return EFalse. If no filename is specified, the path should end in a backslash.

Examples of valid paths (returning ETrue): C:\; \; C:.txt; C:\; .dat

Examples of invalid paths (returning EFalse): C:\; ..\; C:*card\; C:>File.txt

Parameters

RFs &aFs

A connected session with the file server.

const TDesC &aFolderName

A path specifying the folder to test for.

Return value

TBool

ETrue if the folder specified in aFolderName exists, EFalse if not. EFalse is also returned if the specified path is badly formed.


FolderNameFromFullName()

static IMPORT_C TFileName FolderNameFromFullName(const TDesC &aFullName);

Description

Gets the folder name from a path.

A valid full name should have a drive associated with it e.g ("a:\\" - "z:\\")("a:" - "z:")("c:\\system\data\file.txt") Invalid entry will have no drive and cause a panic EBafPanicBadOpenArg For example, if the path is "c:\documents\word\mydoc1", then "word" is returned. "c:" then "c:" is returned "c:\\" then "c:\" is returned "c:\\mydoc1.txt then "c:\" is returned

Parameters

const TDesC &aFullName

A path.

Return value

TFileName

The folder name.


DriveAndPathFromFullName()

static IMPORT_C TFileName DriveAndPathFromFullName(const TDesC &aFullName);

Description

Gets the drive letter and path from a file name.

This is in the form: drive-letter:\path\. The drive letter is folded using class TCharF.

Parameters

const TDesC &aFullName

File name

Return value

TFileName

The drive and path


RootFolderPath()

static IMPORT_C TFileName RootFolderPath(const TBuf< 1 > aDriveLetter);

Description

Gets the root folder for the specified drive.

If aDriveLetter is an alphabet(lowercase or uppercase) then it will return the TFileName which is simply the drive letter plus ":\" If this is not the case, the function will panic with panic code EBafPanicBadOpenArg

Parameters

const TBuf< 1 > aDriveLetter

Drive letter

Return value

TFileName

Root folder


AbbreviateFileName()

static IMPORT_C void AbbreviateFileName(const TFileName &aOriginalFileName, TDes &aAbbreviatedFileName);

Description

Abbreviates a file name.

If aOriginalFileName is less than the maximum length of aAbbreviatedFileName, then the name is simply copied to aAbbreviatedFileName.

If this is not so, then the left-most characters of aOriginalFileName are copied to aAbbreviatedFileName, up to aAbbreviatedFileName's maximum length-1. aAbbreviatedFileName's first character is set to be an ellipsis.

Parameters

const TFileName &aOriginalFileName

Original file name

TDes &aAbbreviatedFileName

On return, abbreviated file name


UidTypeMatches()

static IMPORT_C TBool UidTypeMatches(const TUidType &aFileUid, const TUidType &aMatchUid);

Description

Tests whether two UID types match.

A match is made if each UID in aMatchUid is either identical to the corresponding one in aFileUid, or is KNullUid.

Parameters

const TUidType &aFileUid

The UID type to match

const TUidType &aMatchUid

The UID type to match against

Return value

TBool

ETrue if the UIDs match, otherwise EFalse


Parse()

static IMPORT_C TInt Parse(const TDesC &aName);

Description

Checks if a specified file name can be parsed.

Parameters

const TDesC &aName

Name to parse

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes


ValidateFolderNameTypedByUserL()

static IMPORT_C TInt ValidateFolderNameTypedByUserL(const RFs &aFs, const TDesC &aFolderNameTypedByUser, const TDesC &aCurrentPath, TFileName &aNewFolderFullName);

Description

Checks if a folder name (without drive or path) is valid and returns the full name of the folder.

Parameters

const RFs &aFs

File server session

const TDesC &aFolderNameTypedByUser

Folder name to check

const TDesC &aCurrentPath

Path to which to add the folder

TFileName &aNewFolderFullName

aFolderNameTypedByUser appended to aCurrentPath

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes


CopyFile()

static IMPORT_C TInt CopyFile(RFs &aFs, const TDesC &aSourceFullName, const TDesC &aTargetFullName, TUint aSwitch=CFileMan::EOverWrite);

Description

Copies one or more files.

For more details,

Parameters

RFs &aFs

File server session

const TDesC &aSourceFullName

Path indicating the file(s) to be copied. Any path components that are not specified here will be taken from the session path.

const TDesC &aTargetFullName

Path indicating the directory into which the file(s) are to be copied

TUint aSwitch

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes.

See also:


RenameFile()

static IMPORT_C TInt RenameFile(RFs &aFs, const TDesC &aOldFullName, const TDesC &aNewFullName, TUint aSwitch=CFileMan::EOverWrite);

Description

Renames or moves one or more files or directories.

It can be used to move one or more files by specifying different destination and source directories. For more details,

Parameters

RFs &aFs

File server session

const TDesC &aOldFullName

Path specifying the file(s) to be renamed.

const TDesC &aNewFullName

Path specifying the new name for the files and/or the new directory. Any directories specified in this path that do not exist will be created.

TUint aSwitch

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes.

See also:


DeleteFile()

static IMPORT_C TInt DeleteFile(RFs &aFs, const TDesC &aSourceFullName, TUint aSwitch=0);

Description

Deletes one or more files.

For more details,

Parameters

RFs &aFs

File server session

const TDesC &aSourceFullName

Path indicating the file(s) to be deleted. May either be a full path, or relative to the session path. Use wildcards to specify more than one file.

TUint aSwitch

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes.

See also:


CheckWhetherFullNameRefersToFolder()

static IMPORT_C TInt CheckWhetherFullNameRefersToFolder(const TDesC &aFullName, TBool &aIsFolder);

Description

Checks if a string is a valid folder name.

Parameters

const TDesC &aFullName

String to check

TBool &aIsFolder

ETrue if aFullName is a valid folder name, otherwise EFalse

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes (probably because aFullName cannot be parsed).


MostSignificantPartOfFullName()

static IMPORT_C TInt MostSignificantPartOfFullName(const TDesC &aFullName, TFileName &aMostSignificantPart);

Description

Gets the folder name if the specified item is a valid folder name, otherwise gets the file name.

Parameters

const TDesC &aFullName

Item to parse

TFileName &aMostSignificantPart

Folder or file name

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes


CheckFolder()

static IMPORT_C TInt CheckFolder(RFs &aFs, const TDesC &aFolderName);

Description

Checks that the specified folder can be opened.

Parameters

RFs &aFs

File server session

const TDesC &aFolderName

Folder to check

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes


DiskIsReadOnly()

static IMPORT_C TInt DiskIsReadOnly(RFs &aFs, const TDesC &aFullName, TBool &aIsReadOnly);

Description

Checks if the specified drive is read-only. Checks that the KMediaAttWriteProtected and EMediaRom flags are both set.

Parameters

RFs &aFs

File server session

const TDesC &aFullName

File name, including drive

TBool &aIsReadOnly

On return, ETrue if the drive is read-only, otherwise EFalse

Return value

TInt

KErrNone if successful, otherwise another of the system-wide error codes


DriveIsReadOnlyInternal()

static IMPORT_C TInt DriveIsReadOnlyInternal(RFs &aFs, const TDesC &aFullName, TBool &aIsReadOnlyInternal);

Description

Checks if the specified drive is read-only and is an internal drive i.e. non-removable. Checks that the KMediaAttWriteProtected and KDriveAttInternal flags are both set.

Parameters

RFs &aFs

File server session

const TDesC &aFullName

File name, including drive

TBool &aIsReadOnlyInternal

On return, ETrue if the drive is read-only and internal, otherwise EFalse

Return value

TInt

KErrNone if successful, otherwise another of the system-wide errors codes


GetDiskListL()

static IMPORT_C void GetDiskListL(const RFs &aFs, CDesCArray &aArray);

Description

Retrieves a list of all drives on the system.

The file server is interrogated for a list of the drive letters for all available drives.

On emulator: The removable media is represented by drive X: .

On hardware: The removable media is represented by drives D: E: F: and G: .

Parameters

const RFs &aFs

A connected session with the file server.

CDesCArray &aArray

On return, contains the drive letters that correspond to the available drives. The drive letters are uppercase and are in alphabetical order.


UpdateDiskListL()

static IMPORT_C void UpdateDiskListL(const RFs &aFs, CDesCArray &aArray, TBool aIncludeRom, TDriveNumber aDriveNumber);

Description

Retrieves a list of all drives present on the system.

The file server is interrogated for a list of the drive letters for all available drives. The drive letter that corresponds to aDriveNumber is added to the list regardless of whether it is present, or is corrupt. Also, the C: drive is forced onto the list, even if corrupt or not present.

On emulator: The removable media is represented by drive X: and is forced onto the list unless removed (F5,F4).

On hardware: The removable media is represented by drives D: E: F: and G: and is forced onto the list regardless of whether it is present, or is corrupt.

Parameters

const RFs &aFs

A connected session with the file server.

CDesCArray &aArray

On return, contains the drive letters that correspond to the available drives. The drive letters are uppercase and are in alphabetical order.

TBool aIncludeRom

Specify ETrue if the ROM drive should be included in the list, EFalse if not.

TDriveNumber aDriveNumber

The drive to force into the list, e.g. the drive in the default path.


RemoveSystemDirectory()

static IMPORT_C void RemoveSystemDirectory(CDir &aDir);

Description

Removes "System" from a list of directory entries.

Parameters

CDir &aDir

Array of directory entries.


IsFirstDriveForSocket()

static IMPORT_C TBool IsFirstDriveForSocket(TDriveUnit aDriveUnit);

Description

Tests whether the specified drive corresponds to the primary partition in a removable media slot.

The function assumes that the D: drive corresponds to the primary partition on socket 0, and that the E: drive corresponds to the primary partition on socket 1 (a socket is a slot for removable media). This mapping may not always be the case because it is set up in the variant layer of the Symbian OS.

This function assumes that the drive mappings are contiguous, starting from drive D: .

On emulator: The removable media is represented by drive X: only.

Parameters

TDriveUnit aDriveUnit

The drive to check.

Return value

TBool

ETrue if the drive is the primary partition in a removable media slot. ETrue is also returned if the drive is A, B or C:. EFalse is returned otherwise.


SortByTable()

static IMPORT_C TInt SortByTable(CDir &aDir, CBaflFileSortTable *aTable);

Description

Sorts files by UID.

The caller supplies a table which specifies the order in which files are to be sorted. The files whose UID3 is the first UID in the table appear first. The files whose UID3 is the UID specified second appear next, and so on. Files whose UID3 is not specified in the table, and directories, appear at the end of the list, with directories preceding the files, and with files sorted in ascending order of UID3.

This function is used for customising how lists of application files are sorted.

Parameters

CDir &aDir

The array of files and directories to sort.

CBaflFileSortTable *aTable

A sort order table containing the UIDs to use in the sort.

Return value

TInt

KErrNone if successful, otherwise one of the standard error codes.


GetDowngradePathL()

static IMPORT_C void GetDowngradePathL(const RFs &aFs, const TLanguage aCurrentLanguage, RArray< TLanguage > &aLanguageArray);

Description

Gets the full language downgrade path for a particular locale.

Parameters

const RFs &aFs

A connected session with the file server.

const TLanguage aCurrentLanguage

The language of the locale for which the language downgrade path is required. This language will always be returned as the first language in aLanguageArray. To get the downgrade path for the language of the current locale, specify the language returned by User::Language().

RArray< TLanguage > &aLanguageArray

On return, contains the language downgrade path.

See also:


PersistLocale()

static IMPORT_C void PersistLocale();

Description

Saves the locale settings in TLocale and the currency symbol to file.


PersistHAL()

static IMPORT_C TInt PersistHAL();

Description

Saves the HAL settings to file. This will start a new executable and saves HAL attributes to a file, little delay because of the creation of new process

Return value

TInt

KErrNone if suceessful, otheriwse system wide error code.


PersistScreenCalibration()

static IMPORT_C void PersistScreenCalibration(const TDigitizerCalibration &aScreenCalibration);

Description

Parameters

const TDigitizerCalibration &aScreenCalibration


InitialiseScreenCalibration()

static IMPORT_C void InitialiseScreenCalibration(RFs &aFs);

Description

Parameters

RFs &aFs


InitialiseHAL()

static IMPORT_C void InitialiseHAL(RFs &aFs);

Description

Initialise the HAL settings from.

Parameters

RFs &aFs


InitialiseLocale()

static IMPORT_C void InitialiseLocale(RFs &aFs);

Description

Parameters

RFs &aFs