SophiaFramework UNIVERSE 5.3 |
The SFXFile class is used to perform the file operations such as creating a file, moving a file, deleting a file, reading or writing data from or into the file storage with or without the stream, retrieving file attribute information, making a temporary file etc.
About MIF File Setting | |
---|---|
Never forget to turn on the File option in the MIF file setting of privilege level. |
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"));
The SFXPath class is used to specify the file path as an argument of a function of the SFXFile class.
Example 15.3. Check whether or not the file exists
Bool b; // return value of the Exists function is of the SFCError type // b: set by Exists function whether the 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 the 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 the IsReadOnly function is of the SFCError type // b: set by IsReadOnly function whether or not specifiled file is ReadOnly 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 | |
---|---|
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 | |
---|---|
The file path that does not duplicate existing ones will be created. |
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |