TheRfs
class represents a session with the file server.
The following code demonstrates the use of the system default
path and the session path and
shows how to connect and disconnect to and from the file server.
Use Connect()
to connect to the file server.
Use DefaultPath()
to get the system default
path.
UseSessionPath()
to set the session path.
Use Close()
to close the file server session when
its use is complete.
_LIT(KDefault,"Default path for fsSession is %S\n");
_LIT(KSession,"Session path for fsSession is %S\n");
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
TFileName path;
User::LeaveIfError(fsSession.DefaultPath(path));
console->Printf(KDefault,&path);
User::LeaveIfError(fsSession.SessionPath(path));
console->Printf(KSession,&path);
...
...
fsSession.Close();
The session path is the path in which, by default, all
operations in the current file server session take place. The path can be
changed by a call toRFs::SetSessionPath()
.
Unlike in some other systems, there is a single system default path, rather than one for each drive: the default path consists of a drive and a path specification.
The system default path is assigned as the session path to new clients when they connect to the file server, so that in the code above, the session and system default paths are the same.
You can make several connections to the file server from the same program, and each can have a different session path.
If a file server session is not closed using the
Close()
function, it will be closed automatically when the thread
which opened it terminates. However, when operations using the file server
session have finished, it is good practice to close all resources
immediately.