Symbian programming Summary-files, streams and databases-file systems and related APIs (1)

Source: Internet
Author: User
Tags create directory

This article was originally prepared by Yang. If you need to reselect the article, please indicate the source. Thank you!

The previous articles introduced some basic knowledge about Symbian programming. Before getting bored, let's learn something interesting: File Processing in Symbian. At the end of the article, we will create a simple directory file manager similar to DOS from the beginning.

Note: The terminal system corresponding to the content described in this article is Series 60 3rd.

I. Symbian OS file system 1. File Name and path name in Symbian OS
  • The naming rules for the file name and Path Name of Symbian OS are similar to Dos/Windows, such as "c: \ resource \ 1.png". The file name and path name can be stored in case insensitive.
  • The file name and path name can beWith Spaces, But cannot contain the following characters: <,>, ",/, |
  • Drive c: system partition, d: virtual buffer disk, e: memory card, z: system read-only drive;
  • The complete path name (including drive letters and subdirectories) of a file or directory cannot exceed 256 characters;

For details, see the SDK documentation:» Symbian OS reference» C ++ component reference» Base F32» RFs

2. Application access path Capability Description

The third version of S60 includes digital signature verification. Applications must use certain system resources to have the corresponding capabilities. These capabilities must pass SymbianSigned signature verification before they can be released. For a description of each capability, see the description of the capability in Symbian S60 3rd.

The application also has restrictions on access to a specific directory. The following table lists the capabilities required to access the corresponding directory:

Directory (including subdirectories) Required capabilities
Read access Write Access
Resource None TCB
Sys AllFiles TCB
/Private/<OwnSID> None None
/Private/<OtherSID> AllFiles AllFiles
/<Other> None None

HereSIDIt refers to the unique Security ID of the application (SecureID). Each application has its own security ID and a unique private directory defined by Security ID, suchC:/private/20000001.. ApplicationSecureIDGenerally. Mmp(If not specifically defined ).

 

Ii. APIs related to operating file systems 1. Connect to the file server and manage the RFs class of the file system

Unlike Windows, Symbian OS has specialized services (processes) to manage file read/write. We use the RFs class to connect to the file server,Operate and access the file system.

RFs is derived from RSessionBase and is a server session class.

  • In the console program, we use the following code to create RFs and connect to the file server:
 1     RFs fs;2     CleanupClosePushL(fs);3     User::LeaveIfError(fs.Connect());4     5     ...6 7     CleanupStack::Pop(&fs);    

  • If we use a GUI application framework, the framework has encapsulated RFs for us and is connected, we only need to obtain it using the following methods:
 RFs& fs = CEikonEnv::Static()->Static()->FsSession();

Note:When the program exits, you must ensure that every manual connection is closed, that is, the RFs: Close () method is used; otherwise, CONE 36 Panic: "Open handles were found during application shutdown" means that there are still system resources not released when the program exits.

RFs is a class for performing operations on the file system. The functions are very simple to use. For details, refer to the SDK documentation. The following lists several common functions:

  • Connect and Close: As mentioned earlier, connecting to the file server and closing the connection; RFs: Connect () and RFs: Close () correspond one by one. The RFs exposed by the GUI application framework in the code above does not need to be closed. The framework is closed when it exits.
  • MkDir and MkDirAll: Create a new directory. MkDir must ensure that the parent directory exists. MkDirAll will check the parent directory and the parent directory, and create them if they do not exist;
  • Rename: Rename a file or directory;
  • RmDir: Delete the directory. The directory must not be empty or root;
  • Att and SetAtt: Get/set file or directory attributes;
  • SessionPath: returns the current path;
  • SetSessionPath: set the current path, which cannot contain the file name;
  • ......
2. RFile class for file operations

The RFs class manages file systems, and the RFile class manages a single file and file content.

The RFile class is derived from RSubSessionBase. It is a server sub-session and needs to communicate with the server on the RFs session.

The following lists several common APIs and provides a simple explanation:

  • Close: Close the file. Similar to other languages, you must call RFile: Flush to write the buffer content to the storage before closing the file.Note: When the RFs of the parent session is closed, the file is also closed.;
  • Open: Open the file. This function is very important. The prototype is:

       IMPORT_C TInt Open(RFs& aFs,const TDesC& aName,TUint aFileMode);

  • Read: reads the file content. This function carries both synchronous and asynchronous functions;
  • Write: Write the content to a file. This function also has a synchronous and asynchronous version;
  • Seek: redirects the object pointer to the specified position of the object according to the redirection mode;
  • Size/SetSize: Get/set the file Size;
  • Att/SetAtt: Get/set file attributes;
  • ......
3. TParse (TParsePtr, TParsePtrC) class for file and path Parsing

TParse and related classes provide a set of functions for detecting and parsing file paths. You can use TParse to obtain the drive letters, extensions, paths, and file names of file paths.

Differences between TParse and TParsePtr (TParsePtrC:

  • TParse does not contain the file path descriptor to be parsed. The Set () method is used to pass the file path descriptor to the TParse class;
  • TParsePtr (TParsePtrC) contains the file path, which is passed in to the constructor.
4. File System and advanced file processing class CFileMan

CFileMan provides many advanced methods, such as copying files in batches, Moving Files in batches, and deleting folders, including all subfolders and files. Most of these methods are asynchronous functions and need to be used together with the active object. This class will be detailed in the next section.

 

3. Small Drill: doscommand directory file manager

Because we have not yet learned the GUI application framework, we should first start with the command line to create a simple doscommand directory file manager, so that you can familiarize yourself with the relevant APIs.

Here, I list the supported commands, functions, and APIs in a table for your reference:

Command Parameters Description APIs used
Cd None Show current path RFs: SessionPath
. Returns the current path without any processing)  
.. Back to parent directory TParse: PopDir
\ Returns the root directory. TParse: Drive
Dir None Lists the files and folders in the current path and displays the attributes and modification time. RFs: GetDir
RFs: Att
RFs: Modified
RFile: Att
RFile: Modified
Path Name Lists the files and folders in the specified path and displays the attributes and modification time.
Type File Name Show File Content RFile: Open
RFile: Read
Md Path Name Create directory RFs: MkDirAll
Rd Path Name Delete directory, directory must be empty RFs: RmDir
Del File Name Delete an object RFs: Delete
Drivers None List all drives (including the volume name) RFs: DriveList
RFs: Volumn
Label Drive name volume name Set the drive volume label RFs: SetVolumnLabel
Ren New file name or path name Change the file or path name RFs: Rename

Click here to download the instance source code

 

 

Iv. References
  1. Series 60 Application Development
  2. Application Development S60 3rd Edition

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.