PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

15.2. Class for Operating a File

SFXFile is the class for operating a file such as creating, moving, deleting, retrieving, etc. Data can be data from or written onto a file through the Stream.

[Caution] About MIF File Setting

Never forget to turn on the File option in the MIF file setting of privilege level.

[Note] Error handling

All the following functions return error values of SFCError type. However, error handling is omitted for simplified explanation.

Example 15.1. Change the file name (or Move file)

SFXFile::Rename(SFXPath("/dir1/data.txt"), SFXPath("/dir2/data.dat"));

SFXPath is used to specify the file path as an argument of SFXFile function.

Example 15.2. Delete the file

SFXFile::Remove(SFXPath("/dir1/data.txt"));

Example 15.3. Check whether the file exists or not

Bool b;

// return value of Exists function is of SFCError type
// b: set by Exists function whether specifiled file exists or not

SFXFile::Exists(SFXPath("/dir1/data.txt"), &b);

if (b) {
    // when file exists

}

Example 15.4. Get the file size

UInt32 size;

SFXFile::GetSize(SFXPath("/dir1/data.txt"), &size); // size: file size set by GetSize function

Example 15.5. Get the file creation date

SFXDate date; // Date instance

// date: file creation date set by GetCreateDate function
SFXFile::GetCreateDate(SFXPath("/dir1/data.txt"), &date);

Example 15.6. Get the device free space

UInt32 space;

SFXFile::DeviceFreeSpace(&space); // space: free space set by DeviceFreeSpace function

Example 15.7. Check whether the file is read only or not

Bool b;

// return value of IsReadOnly function is of SFCError type
// b: set by IsReadOnly function whether specifiled file is ReadOnly or not

SFXFile::IsReadOnly(SFXPath("/dir1/data.txt"), &b);

if (b) {
    // when file is ReadOnly

}

Example 15.8. Get the temporary file path

SFXPath path;
SFXPath parentPath;

parentPath.Set(SFXAnsiString("/"));

SFXFile::GetTemporaryPath(parentPath, &path);
// file path like "/sfx7182CBD4.tmp" will be created
[Note] Note
The file path that does not duplicate existing ones will be created for a temporary file.

Example 15.9. Get the unique file path

SFXPath path;
SFXPath parentPath;

parentPath.Set(SFXAnsiString("/"));

SFXFile::GetUniquePath(parentPath, "data", ".txt", &path);
// file path like "/data829AE714.txt" will be created
[Note] Note

The file path that does not duplicate existing ones will be created.