1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __EIKFUTIL_H__
17 #define __EIKFUTIL_H__
26 class CBaflFileSortTable;
27 class TResourceReader;
30 /** Provides a set of drive, path and file utility functions.
32 This class is essentially a thin layer over the BaflUtils class.
36 NONSHARABLE_CLASS(EikFileUtils)
39 inline static TBool PathExists(const TDesC& aPath);
40 inline static TInt IsFolder(const TDesC& aFullName, TBool& aIsFolder);
41 inline static TBool FolderExists(const TDesC& aFolderName);
42 inline static TFileName FolderNameFromFullName(const TDesC& aFullName);
43 inline static TFileName DriveAndPathFromFullName(const TDesC& aFullName);
44 inline static TFileName RootFolderPath(const TBuf<1> aDriveLetter);
45 inline static void AbbreviateFileName(const TFileName& aOriginalFileName, TDes& aAbbreviatedFileName);
46 IMPORT_C static TFileName AbbreviatePath(TDesC& aPathName, const CFont& aFont, TInt aMaxWidthInPixels);
47 inline static TBool UidTypeMatches(const TUidType& aFileUid, const TUidType& aMatchUid);
48 inline static TInt Parse(const TDesC& aName);
49 IMPORT_C static TFileName ValidateFolderNameTypedByUserL(const TDesC& aFolderNameTypedByUser, const TDesC& aCurrentPath);
50 inline static TInt CopyFile(const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch = CFileMan::EOverWrite);
51 inline static TInt RenameFile(const TDesC& aOldFullName, const TDesC& aNewFullName, TUint aSwitch = CFileMan::EOverWrite);
52 inline static TInt DeleteFile(const TDesC& aSourceFullName, TUint aSwitch=0);
53 inline static TInt CheckWhetherFullNameRefersToFolder(const TDesC& aFullName, TBool& aIsFolder);
54 inline static TInt MostSignificantPartOfFullName(const TDesC& aFullName, TFileName& aMostSignificantPart);
55 inline static TInt CheckFolder(const TDesC& aFolderName);
56 inline static TInt DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly);
57 inline static void UpdateDiskListL(const RFs& aFs,CDesCArray& aArray,TBool aIncludeRom,TDriveNumber aDriveNumber);
58 inline static void RemoveSystemDirectory(CDir& aDir);
59 inline static TBool IsFirstDriveForSocket(TDriveUnit aDriveUnit);
60 inline static TInt SortByTable(CDir& aDir,CBaflFileSortTable* aTable);
66 /** Tests whether a path exists.
68 @param aPath The path to check.
69 @return ETrue if the path exists, EFalse otherwise. */
70 inline TBool EikFileUtils::PathExists(const TDesC& aPath)
71 { return BaflUtils::PathExists(CEikonEnv::Static()->FsSession(),aPath); }
73 /** Tests whether aFullName is a folder.
75 @param aFullName The drive and path to test.
76 @param aIsFolder On return, indicates whether aFullName is a folder.
77 @return KErrNone if successful otherwise another of the system-wide error codes. */
78 inline TInt EikFileUtils::IsFolder(const TDesC& aFullName, TBool& aIsFolder)
79 { return BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), aFullName,aIsFolder); }
81 /** Tests whether a specified folder exists.
83 This returns a boolean value indicating whether the folder exists: see also
84 CheckFolder() which returns an error code instead.
86 @param aFolderName The folder's path.
87 @return ETrue if the folder exists, EFalse if not. */
88 inline TBool EikFileUtils::FolderExists(const TDesC& aFolderName)
89 { return BaflUtils::FolderExists(CEikonEnv::Static()->FsSession(), aFolderName); }
91 /** Gets a folder name from a path and file name.
93 @param aFullName The full path and file name from which the folder will be
95 @return Folder name */
96 inline TFileName EikFileUtils::FolderNameFromFullName(const TDesC& aFullName)
97 { return BaflUtils::FolderNameFromFullName(aFullName); }
99 /** Parses the specified full path and file name to obtain the drive and path.
101 @param aFullName The full path and file name from which the drive and path
103 @return The drive and path. */
104 inline TFileName EikFileUtils::DriveAndPathFromFullName(const TDesC& aFullName)
105 { return BaflUtils::DriveAndPathFromFullName(aFullName); }
107 /** Gets the root folder for the specified drive.
109 @param aDriveLetter The drive letter, C for example.
110 @return The root folder for the drive, C:\ for example. */
111 inline TFileName EikFileUtils::RootFolderPath(const TBuf<1> aDriveLetter)
112 { return BaflUtils::RootFolderPath(aDriveLetter); }
114 /** Abbreviates a file name.
116 If aOriginalFileName is less than the maximum length of aAbbreviatedFileName,
117 then the name is simply copied to aAbbreviatedFileName.
119 If this is not the case, then the left-most characters of aOriginalFileName are
120 copied to aAbbreviatedFileName, up to aAbbreviatedFileName's maximum length-1 and
121 aAbbreviatedFileName's first character is set to be an ellipsis.
123 For example, if c:\\home\\letters\\abcdef is the original file name and aAbbreviatedFileName
124 allows only 7 characters, the abbreviated file name will be ...abcdef.
125 This can be used to display a file or folder name in an error or progress
128 @param aOriginalFileName Original file name.
129 @param aAbbreviatedFileName On return, the abbreviated file name. */
130 inline void EikFileUtils::AbbreviateFileName(const TFileName& aOriginalFileName, TDes& aAbbreviatedFileName)
131 { BaflUtils::AbbreviateFileName(aOriginalFileName,aAbbreviatedFileName); }
133 /** Tests whether two UID types match.
135 A match is made if each UID in aMatchUid is either identical to the corresponding
136 one in aFileUid, or is KNullUid.
138 @param aFileUid The UID type to match.
139 @param aMatchUid The UID type to match against.
140 @return ETrue if the UIDs match, EFalse if not. */
141 inline TBool EikFileUtils::UidTypeMatches(const TUidType& aFileUid, const TUidType& aMatchUid)
142 { return BaflUtils::UidTypeMatches(aFileUid,aMatchUid); }
144 /** Tests whether a specified file name can be parsed.
146 @param aName The file name to parse.
147 @return KErrNone if the filename can be parsed, otherwise one
148 of the system-wide error codes.
150 inline TInt EikFileUtils::Parse(const TDesC& aName)
151 { return BaflUtils::Parse(aName); }
153 /** Copies the specified file.
157 - files can be copied across drives
159 - open files can be copied only if they have been opened using the EFileShareReadersOnly
162 - the source file's attributes are preserved in the target file
164 @param aSourceFullName Path indicating the file(s) to be copied. Any path
165 components which are not specified here will be taken from the session path.
166 @param aTargetFullName Path indicating the directory into which the file(s)
168 @param aSwitch Optional switch to allow overwriting files with the same name
169 in the target directory, or recursion. By default, this function operates with
170 overwriting and non-recursively. Switch options are defined using the enum TSwitch.
171 If recursive operation is set, any intermediate directories are created. If no overwriting
172 is set, any files with the same name are not overwritten, and an error is returned
174 @return KErrNone if the copy is successful, otherwise another of the system-wide
176 inline TInt EikFileUtils::CopyFile(const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
177 { return BaflUtils::CopyFile(CEikonEnv::Static()->FsSession(),aSourceFullName,aTargetFullName,aSwitch); }
179 /** Renames one or more files or directories.
181 This can also be used to move files by specifying different destination and
182 source directories, but note that the destination and source directories must be
185 If moving files, you can set aSwitch so that any files with the same name
186 that exist in the target directory are overwritten. If aSwitch is set for
187 no overwriting, any files with the same name are not overwritten, and an error
188 (KErrAlreadyExists) is returned for that file.
190 This function can only operate non-recursively, so that only the matching
191 files located in the single directory specified by aOldFullName may be renamed.
193 Read-only, system and hidden files may be renamed or moved, and the source
194 file's attributes are preserved in the target file, but attempting to rename
195 or move an open file will return an error for that file.
197 @param aOldFullName Path specifying the file or directory to be renamed.
198 @param aNewFullName Path specifying the new name for the file or directory.
199 Any directories specified in this path which do not exist will be created.
200 @param aSwitch Optional, sets whether files are overwritten on the target.
201 @return KErrNone if successful otherwise another of the system-wide error codes. */
202 inline TInt EikFileUtils::RenameFile(const TDesC& aOldFullName, const TDesC& aNewFullName, TUint aSwitch)
203 { return BaflUtils::RenameFile(CEikonEnv::Static()->FsSession(),aOldFullName,aNewFullName,aSwitch); }
205 /** Deletes one or more files.
207 This function may operate recursively or non-recursively. When operating non-recursively,
208 only the matching files located in the directory specified in aSourceFullName
209 are affected. When operating recursively, all matching files in the directory
210 hierarchy below the directory specified in aSourceFullName are deleted.
212 Attempting to delete read-only or open files returns an error.
214 @param aSourceFullName Path indicating the file(s) to be deleted. This can
215 either be a full path, or a path relative to the session path. Use wildcards
216 to specify more than one file.
217 @param aSwitch Determines whether this function operates recursively. By default,
218 this function operates non-recursively.
219 @return KErrNone if aSourceFullName is successfully deleted, otherwise another
220 of the system-wide error codes. */
221 inline TInt EikFileUtils::DeleteFile(const TDesC& aSourceFullName, TUint aSwitch)
222 { return BaflUtils::DeleteFile(CEikonEnv::Static()->FsSession(), aSourceFullName,aSwitch); }
224 /** Tests whether a file specification is a valid folder name.
226 @param aFullName The string to check.
227 @param aIsFolder True if aFullName is a valid folder name, otherwise false.
228 @return KErrNone if successful, otherwise another of the system-wide error codes
229 (probably because aFullName cannot be parsed). */
230 inline TInt EikFileUtils::CheckWhetherFullNameRefersToFolder(const TDesC& aFullName, TBool& aIsFolder)
231 { return BaflUtils::CheckWhetherFullNameRefersToFolder(aFullName,aIsFolder); }
233 /** Gets the folder name if the specified item is a valid folder name, otherwise gets the file name.
235 @param aFullName Item to parse.
236 @param aMostSignificantPart On return, the folder or file name.
237 @return KErrNone if successful otherwise another of the system-wide error codes. */
238 inline TInt EikFileUtils::MostSignificantPartOfFullName(const TDesC& aFullName, TFileName& aMostSignificantPart)
239 { return BaflUtils::MostSignificantPartOfFullName(aFullName,aMostSignificantPart); }
241 /** Tests whether the specified folder exists and can be opened.
243 This returns an error code if the folder does not exist: see also FolderExists()
244 which returns a boolean value.
246 @param aFolderName The folder's name and path.
247 @return KErrNone if aFolderName exists, otherwise another of the system-wide
249 inline TInt EikFileUtils::CheckFolder(const TDesC& aFolderName)
250 { return BaflUtils::CheckFolder(CEikonEnv::Static()->FsSession(),aFolderName); }
252 /** Tests whether the specified drive is read-only.
254 @param aFullName File name, including drive.
255 @param aIsReadOnly On return, true if the drive is read-only, otherwise false.
256 @return KErrNone if successful otherwise another of the system-wide error codes. */
257 inline TInt EikFileUtils::DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly)
258 { return BaflUtils::DiskIsReadOnly(CEikonEnv::Static()->FsSession(),aFullName,aIsReadOnly); }
260 /** Gets a list of all drives present on the system.
262 The file server is interrogated for a list of the drive letters for all available
263 drives. The drive letter that corresponds to aDriveNumber is added to the list
264 regardless of whether it is present, or is corrupt. Also, the C: drive and the
265 primary partitions on removable media slots are forced onto the list, even if
266 corrupt or not present.
268 @param aFs A connected session with the file server.
269 @param aArray On return, contains the drive letters that correspond to the available
270 drives. The drive letters are uppercase and are in alphabetical order.
271 @param aIncludeRom ETrue if the ROM is included as a drive, EFalse otherwise.
272 @param aDriveNumber The drive to force into the list, e.g. the drive in the default
274 inline void EikFileUtils::UpdateDiskListL(const RFs& aFs,CDesCArray& aArray,TBool aIncludeRom,TDriveNumber aDriveNumber)
275 { BaflUtils::UpdateDiskListL(aFs,aArray,aIncludeRom,aDriveNumber); }
277 /** Removes the System directory from a list of directory entries.
279 @param aDir Array of directory entries. */
280 inline void EikFileUtils::RemoveSystemDirectory(CDir& aDir)
281 { BaflUtils::RemoveSystemDirectory(aDir); }
283 /** Tests whether the specified drive corresponds to the primary partition
284 in a removable media slot.
286 Note that the function assumes that the D: drive corresponds to the primary
287 partition on socket 0, and that the E: drive corresponds to the primary
288 partition on socket 1 (a socket is a slot for removable media). This mapping
289 may not always be the case because it is set up in the variant layer of Symbian
292 @param aDriveUnit The drive to check.
293 @return True if the drive is the primary partition in a removable media
294 slot. True is also returned if the drive is C:. False is returned otherwise. */
295 inline TBool EikFileUtils::IsFirstDriveForSocket(TDriveUnit aDriveUnit)
296 { return BaflUtils::IsFirstDriveForSocket(aDriveUnit); }
298 /** Sorts files by UID.
300 The caller supplies a table which specifies the order in which files are to be sorted.
301 The files whose UID3 is the first UID in the table appear first. The files whose UID3
302 is the UID specified second appear next, and so on. Files whose UID3 is not specified
303 in the table, and directories, appear at the end of the list, with directories preceding
304 the files, and with files sorted in ascending order of UID3.
306 This function is used for customising how lists of application files are sorted.
308 @param aDir The array of files and directories to sort.
309 @param aTable A sort order table containing the UIDs to use in the sort.
310 @return KErrNone if successful otherwise another of the system-wide error codes. */
311 inline TInt EikFileUtils::SortByTable(CDir& aDir,CBaflFileSortTable* aTable)
312 { return BaflUtils::SortByTable(aDir,aTable); }
315 #endif // __EIKFUTIL_H__