»
UIQ 3.1 SDK »
Symbian OS v9.2 »
Symbian OS reference »
C++ component reference »
Syslibs BAFL »
BaflUtils
Location:
BAUTILS.H
Link against: bafl.lib
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(), IdealLanguage(), InitialiseHAL(), InitialiseLocale(), InitialiseScreenCalibration(), IsFirstDriveForSocket(), IsFolder(), MostSignificantPartOfFullName(), NearestLanguageFile(), NearestLanguageFile(), Parse(), PathExists(), PersistHAL(), PersistLocale(), PersistScreenCalibration(), ReleaseIdealLanguage(), RemoveSystemDirectory(), RenameFile(), RootFolderPath(), SetIdealLanguage(), SortByTable(), UidTypeMatches(), UpdateDiskListL(), ValidateFolderNameTypedByUserL()
See also:
Member functions
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 |
|
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 |
|
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
Return value
See also:
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. |
|
See also:
BaflUtils::NearestLanguageFile(const RFs& aFs,TFileName& aName, TLanguage& aLanguage)
static IMPORT_C void NearestLanguageFile(const RFs &aFs, TFileName &aName, TLanguage &aLanguage);
Description
Searches for the file with the correct language extension for the language of the current locale, or failing this, the best matching file. Also returns the language of the best matching file if one is found.
Symbian defines two-digit language values that identify natural languages. These values are enumerated by the TLanguage enum. It is suggested that files that have language-specific variants, such as resource files, have extensions in which the last two digits are the language code. For example, somefile.r01 and somefile.r02 would be the English and French versions of the resource file somefile. In a system set to the English locale, this function would return somefile.r01; in a French locale, somefile.r02.
From Symbian OS v7.0, this function uses the language downgrade path.
The language downgrade path is an array of up to eight TLanguage values. The first one is the language of the current locale. Up to the next three can be customised using TLocale::SetLanguageDowngrade(). The rest of the downgrade path is based on a table of language near equivalence which is internal to Symbian.
The languages in the downgrade path are used in turn to find the best matching language-specific version of the language-neutral file specified in aName. The full language downgrade path can be retrieved using GetDowngradePathL(). The next language in the path is used if no file can be found with the extension for the current language in the path.
For each language, the first drive searched is the preset writeable drive which holds customised resource files, followed by the drive specified in the aName argument. A maximum of 2 drives are searched. Note that the preset writeable drive may not be set on some devices, particularly if all customised resource files are held in ROM.
From Symbian OS v7.0s, this function specifies the form of names passed.
A valid name can be of the form:
name.nameTn name.nameT nameT
Where 'name' are alphanumeric characters, '.' is optional, 'T' is a non-digit, and where 'n' are a list of upto 5 numeric characters.
Invalid filenames are any filename whose length (minus path) must be greater than KInvNameAndMinSuffixLength, and whose form is purely numerical, i.e. '1234'
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. |
TLanguage &aLanguage |
Parm to hold language. On return, this is set to the language of the file found. If no such file is found the language is set ELangNone |
|
See also:
static IMPORT_C TInt SetIdealLanguage(TLanguage aLanguage);
Description
Parameters
Return value
static IMPORT_C TLanguage IdealLanguage();
Description
Return value
static IMPORT_C void ReleaseIdealLanguage();
Description
| Interface status: | deprecated | This method has been replaced by (and now internally calls) RFs:GetSystemDrive, which always returns a valid drive number. |
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. |
|
See also:
BaflUtils::NearestLanguageFile
RFs::GetSystemDrive
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. |
|
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 |
|
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 FFalse.
A filename may be specified in the path, and is ignored, but note that if a filename is included in the path, its name must not contain any illegal characters - this is considered a badly formed path and causes the function to return EFalse. If no filename is specified, the path should end in a backslash.
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. |
|
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
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
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
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 |
|
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 |
|
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 |
|
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:
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:
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 |
|
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 |
|
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 |
|
See also:
BaflUtils::DriveIsReadOnlyInternal
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 |
|
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. |
|
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. |
|
static IMPORT_C void RemoveSystemDirectory(CDir &aDir);
Description
Removes "System" from a list of directory entries.
Parameters
CDir &aDir |
Array of directory entries. |
|
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
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. |
|
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. |
|
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:
| Interface status: | deprecated | 9.1 Persistence and initialisation of system locale data will be performed transparently by a separate executable (InilialiseLocale.exe) wich should be loaded as part of the system start procedure. |
static IMPORT_C void PersistLocale();
Description
Saves the locale settings in TLocale and the currency symbol to file.
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
| Interface status: | deprecated | 9.1 This function is empty |
static IMPORT_C void InitialiseHAL(RFs &aFs);
Description
Initialise the HAL settings from.
Parameters
static IMPORT_C void InitialiseLocale(RFs &aFs);
Description
Parameters