PrevNextUpHome SophiaFramework UNIVERSE 5.3

15.4. Class for Operating a File Path and a Directory Path

SFXPath is the class for operating a file path. The arguments of file path specified in the functions of SFXFile and SFXDirectory classes are of SFXPath type.

Example 15.22. Define the path

SFXPath path1("/dir1/data.txt");

SFXPath path2("dir1/dir2/");

In the above example, the argument ending with the separator ('/') character represents a directory. A file name dose not end with the separator ('/') character.

Example 15.23. Check whether or not it is a directory

if (path.IsDirectory()) {
    // when path denotes a directory

if (path.IsRootDirectory()) {
    // when path denotes a root directory

if (path.IsHomeDirectory()) {
    // when path denotes a home directory
[Note] Note
The SFXPath::IsDirectory function returns false if path is "/dir1/data.txt", while it returns true if path is "/dir1/dir2/". The path string is used to check regardless of the file existence.

Example 15.24. Get the parent directory

SFXPath path1("/dir1/dir2/data.txt");
SFXPath path2;
SFXAnsiString string;

// path2 is "/dir1/dir2/", path1 is not changed
path2 = path1.GetParentPath();

// this function returns a string
string = path1.GetParent();

There are two functions: one is a function returning the SFXPath instance, and the other is a function returning the SFXAnsiString instance.

Example 15.25. Get the absolute path

SFXPath path1("dir1/dir2/data.txt");
SFXPath path2;

// path2 = "/dir1/dir2/data.txt" 
// path1 is not changed
path2 = path1.GetAbsolutePath();
[Caution] Root path

The root path varies according to the BREW versions.

It is "/" in BREW 2.1 or below and "fs:/" in BREW 3.1 or above.

Example 15.26. Get the file extension

SFXPath path("/dir1/dir2/data.txt");
SFXAnsiString extension;

// get the file extension (extension = "txt")
extension = path.GetExtension();

Example 15.27. Normalize the path

SFXPath path1("/dir1/../dir2/./../dir3/./data.txt");
SFXPath path2;

path2 = path1.NormalizePath(); // path2 = "/dir3/data.txt"