Enables access to the file system.
The File class provides extensive support for file management and I/O. The class supports the notion of individual file compression and file finding capabilities. Since all File objects are tracked, there is no chance of the system leaving locked files behind after a program exits. Folder management is also integrated into this class to ease the management of both file types.
To read or write to a file, set the Path of the file as well as the correct I/O file flags before initialisation. See the Flags field for information on the available I/O flags. Functionality for read and write operations is provided through the Read() and Write() actions. The Seek() action can be used to change the read/write position in a file.
The File class consists of the following fields:
Access | Name | Type | Comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Buffer | BYTE * | Points to the internal data buffer if the file content is held in memory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If a file has been created with an internal buffer (by setting the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Created | APTR | The creation date stamp for the file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Created field returns the time at which the file was first created, if supported by the filesystem. If not supported directly, the most recent 'modification date' is normally returned. To simplify time management, information is read and set via a DateTime structure. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Date | APTR | The 'last modified' date stamp on the file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Date field reflects the time at which the file was last modified. It can also be used to set a new modification date. Please note that if the file is open for writing, then date-stamped, then modified; the file system driver will overwrite the previously defined date stamp with the time at which the file was last written. Information is read and set using a standard DateTime structure. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Flags | FL | File flags and options. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Group | INT | Retrieve or change the group ID of a file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The group ID assigned to a file can be read from this field. The ID is retrieved from the file system in real time in case the ID has been changed after initialisation of the file object. You can also change the group ID of a file by writing an integer value to this field. If the file system does not support group ID's, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Handle | BIGINT | The native system handle for the file opened by the file object. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This field returns the native file system handle for the file opened by the file object. The native handle may be an integer or pointer value in 32 or 64-bit format. In order to manage this issue in a multi-platform manner, the value is returned as a 64-bit integer. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Icon | STRING | Returns an icon reference that is suitable for this file in the UI. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This field returns the name of the best icon to use when representing the file to the user, for instance in a file list. The icon style is determined by analysing the File's Path. The resulting string is returned in the format | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Link | STRING | Returns the link path for symbolically linked files. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If a file represents a symbolic link (indicated by the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Path | STRING | Specifies the location of a file or folder. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This field is required for initialisation and must either be in the format of a universal path string, or a path that is compatible with the host system. The standard format for a universal path is To reference a folder in a way that is distinct from a file, use a trailing slash as in Referencing a The accepted method for referencing parent folders is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Permissions | INT | Manages the permissions of a file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Position | BIGINT | The current read/write byte position in a file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This field indicates the current byte position of an open file (this affects read and write operations). Writing to this field performs a Seek() operation. The Position will always remain at zero if the file object represents a folder. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ResolvedPath | STRING | Returns a resolved copy of the Path string. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The ResolvedPath will return a resolved copy of the Path string. The resolved path will be in a format that is native to the host platform. Please refer to the ResolvePath() function for further information. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Size | BIGINT | The byte size of a file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The current byte size of a file is indicated by this field. If the file object represents a folder, the Size value will be zero. You can also truncate a file by setting the Size; this will result in the current read/write position being set to the end of the file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Static | INT | Set to true if a file object should be static. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This field applies when a file object has been created in an object script. By default, a file object will auto-terminate when a closing tag is received. If the object must remain live, set this field to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Target | OBJECTID | Specifies a surface ID to target for user feedback and dialog boxes. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
User feedback can be enabled for certain file operations by setting the Target field to a valid surface ID, or zero for the default target for new windows. This field is set to If set correctly, operations such as file deletion or copying will pop-up a progress box after a certain amount of time has elapsed during the operation. The dialog box will also provide the user with a cancel option to terminate the process early. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TimeStamp | BIGINT | The last modification time set on a file, represented as a 64-bit integer. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The TimeStamp field is a 64-bit representation of the last modification date/time set on a file. It is not guaranteed that the value represents seconds from the epoch, so it should only be used for purposes such as sorting, or for comparison to the time stamps of other files. For a parsed time structure, refer to the Date field. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
User | INT | Retrieve or change the user ID of a file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The user ID assigned to a file can be read from this field. The ID is retrieved from the file system in real time in case the ID has been changed after initialisation of the file object. You can also change the user ID of a file by writing an integer value to this field. This can only be done post-initialisation or an error code will be returned. If the filesystem does not support user ID's, |
The following actions are currently supported:
Name | Comment | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Activate | Opens the file. Performed automatically if NEW , READ or WRITE flags were specified on initialisation. | |||||||||||||||||||||||||
DataFeed | Data can be streamed to any file as a method of writing content. | |||||||||||||||||||||||||
ERR acDataFeed(*Object, OBJECTID Object, DATA Datatype, APTR Buffer, LONG Size)
Streaming data of any type to a file will result in the content being written to the file at the current seek Position. | ||||||||||||||||||||||||||
Init | Initialises a file. | |||||||||||||||||||||||||
ERR InitObject(*Object) This action will prepare a file or folder at the given Path for use. To create a new file from scratch, specify the To read and write data to the file, specify the If neither of the The File class supports RAM based file buffering - this is activated by using the Strings can also be loaded into file buffers for read/write access. This is achieved by specifying the Path Error Codes
| ||||||||||||||||||||||||||
Query | Read a file's meta information from source. | |||||||||||||||||||||||||
Read | Reads data from a file. | |||||||||||||||||||||||||
ERR acRead(*Object, APTR Buffer, LONG Length, LONG *Result)
Reads data from a file into the given buffer. Increases the value in the Position field by the amount of bytes read from the file data. The It is normal behaviour for this call to report success in the event that no data has been read from the file, e.g. if the end of the file has been reached. The Error Codes
| ||||||||||||||||||||||||||
Rename | Changes the name of a file. | |||||||||||||||||||||||||
ERR acRename(*Object, CSTRING Name)
| ||||||||||||||||||||||||||
Reset | If the file represents a folder, the file list index is reset by this action. | |||||||||||||||||||||||||
Seek | Seeks to a new read/write position within a file. | |||||||||||||||||||||||||
ERR acSeek(*Object, DOUBLE Offset, LONG Position)
| ||||||||||||||||||||||||||
Write | Writes data to a file. | |||||||||||||||||||||||||
ERR acWrite(*Object, APTR Buffer, LONG Length, LONG Result)
Writes data from the provided buffer into the file, then updates the Position field to reflect the new read/write position. You must have set the Error Codes
|
The following methods are currently supported:
Name | Comment | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BufferContent | Reads all file content into a local memory buffer. | ||||||||||||||||||||||||||||||||||||
ERR fl::BufferContent(OBJECTPTR Object) File content may be buffered at any time by calling the BufferContent method. This will allocate a buffer that matches the current file size and the file's content will be read into that buffer. The Once a file has been buffered, the original file handle and any locks on that file are returned to the system. Physical operations on the file object such as delete, rename and attribute settings no longer have meaning when applied to a buffered file. It is not possible to drop the buffer and return the file object to its original state once buffering has been enabled. Error Codes
| |||||||||||||||||||||||||||||||||||||
Copy | Copies the data of a file to another location. | ||||||||||||||||||||||||||||||||||||
ERR fl::Copy(OBJECTPTR Object, CSTRING Dest, FUNCTION * Callback)
This method is used to copy the data of a file object to another location. All of the data will be copied, effectively creating a clone of the original file information. The file object must have been initialised with the The Position field will be reset as a result of calling this method. When copying directories with this method, the entire folder structure (i.e. all of the folder contents) will be copied to the new location. If an error occurs when copying a sub-folder or file, the procedure will be aborted and an error code will be returned. Error Codes
| |||||||||||||||||||||||||||||||||||||
Delete | Deletes a file from its source location. | ||||||||||||||||||||||||||||||||||||
ERR fl::Delete(OBJECTPTR Object, FUNCTION * Callback)
This method is used to delete files from their source location. If used on a folder, all of the folder's contents will be deleted in the call. Once a file is deleted, the object effectively becomes unusable. For this reason, file deletion should normally be followed up with a call to the Free action. Error Codes
| |||||||||||||||||||||||||||||||||||||
Move | Moves a file to a new location. | ||||||||||||||||||||||||||||||||||||
ERR fl::Move(OBJECTPTR Object, CSTRING Dest, FUNCTION * Callback)
This method is used to move the data of a file to another location. If the file object represents a folder, then the folder and all of its contents will be moved. The file object must have been initialised with the The Position field will be reset as a result of calling this method. Error Codes
| |||||||||||||||||||||||||||||||||||||
Next | Retrieve meta information describing the next indexed file in the folder list. | ||||||||||||||||||||||||||||||||||||
ERR fl::Next(OBJECTPTR Object, objFile ** File)
If a file object represents a folder, calling the Next() method will retrieve meta information about the next file in the folder's index. This information will be returned as a new File object that is partially initialised (the file will not be opened, but information such as size, timestamps and permissions will be retrievable). If desired, the resulting file object can be opened by setting the It is the responsibility of the caller to free the resulting File object once it is no longer required. The file index can be reset by calling the Reset() action. Error Codes
| |||||||||||||||||||||||||||||||||||||
ReadLine | Reads the next line from the file. | ||||||||||||||||||||||||||||||||||||
ERR fl::ReadLine(OBJECTPTR Object, STRING * Result)
Reads one line from the file into an internal buffer, which is returned in the Result argument. Reading a line will increase the Position field by the amount of bytes read from the file. You must have set the The line buffer is managed internally, so there is no need to free the Error Codes
| |||||||||||||||||||||||||||||||||||||
SetDate | Sets the date on a file. | ||||||||||||||||||||||||||||||||||||
ERR fl::SetDate(OBJECTPTR Object, LONG Year, LONG Month, LONG Day, LONG Hour, LONG Minute, LONG Second, FDT Type)
The SetDate method provides a convenient way to set the date and time information for a file object. Date information is set in a human readable year, month, day, hour, minute and second format for your convenience. Depending on the filesystem type, multiple forms of datestamp may be supported. The default datestamp,
If the specified datestamp is not supported by the filesystem, Error Codes
| |||||||||||||||||||||||||||||||||||||
StartStream | Starts streaming data from a file source. | ||||||||||||||||||||||||||||||||||||
ERR fl::StartStream(OBJECTPTR Object, OBJECTID Subscriber, FL Flags, LONG Length)
If a file object is a stream (indicated by the A single file object can support read or write streams (pass A stream can be limited by setting the Length parameter to a non-zero value. If the StartStream request is successful, the file object will return action notifications to the Subscriber to indicate activity on the file stream. When reading from a stream, When writing to a stream, A stream can be cancelled at any time by calling StopStream(). Error Codes
| |||||||||||||||||||||||||||||||||||||
StopStream | Stops streaming data from a file source. | ||||||||||||||||||||||||||||||||||||
ERR fl::StopStream(OBJECTPTR Object) This method terminates data streaming from a file (instantiated by the StartStream() method). Any resources related to the streaming process will be deallocated. Error Codes
| |||||||||||||||||||||||||||||||||||||
Watch | Monitors files and folders for file system events. | ||||||||||||||||||||||||||||||||||||
ERR fl::Watch(OBJECTPTR Object, FUNCTION * Callback, LARGE Custom, MFF Flags)
The Watch() method configures event based reporting for changes to any file or folder in the file system. The capabilities of this method are dependent on the host platform, with Windows and Linux systems being able to support most of the current feature set. The path that will be monitored is determined by the File object's Path field. Both files and folders are supported as targets. The optional MFF Flags are used to filter events to those that are desired for monitoring. The client must provide a Each event will be delivered in the sequence that they are originally raised. The If the callback routine returns Error Codes
|
Flags for the SetDate() file method.
Name | Description |
---|---|
FDT::ACCESSED | The date on which the file was last accessed by a user or application. |
FDT::ARCHIVED | The date on which the file was most recently archived. Not supported by most filesystems. |
FDT::CREATED | The date on which the file was created. On some host platforms this datestamp may be read-only. |
FDT::MODIFIED | The date on which the file was last modified. |
File flags
Name | Description |
---|---|
FL::APPROXIMATE | Allows fuzzy matching of the file path when opening an existing file. This means that the file extension will be ignored; for instance attempting to open a file of 'screenshot.png' when only a file name of 'screenshot.jpg' exists in the same folder, the 'screenshot.jpg' file will be opened instead. If multiple files could potentially match to the file name, the file object will select the first match that is encountered. |
FL::BUFFER | Activates a special mode in which the file data is stored in a memory buffer rather than a disk file. Set the Size field to a value of at least 1 so that the initial buffer size is configured. In this mode many of the available file operations are meaningless except for the Read, Write and Seek actions. |
FL::DEVICE | The file is a system device (must set if opening a device for read/write operations) |
FL::DIRECTORY | The file object represents a folder. |
FL::EXCLUDE_FILES | Exclude files when scanning this folder. |
FL::EXCLUDE_FOLDERS | Exclude folders when scanning this folder. |
FL::FILE | Explicitly declares the file object as an entity that stores content (as opposed to a device or folder for example). |
FL::FOLDER | The file object represents a folder. |
FL::LINK | Read-Only. Indicates that the file is a symbolic link or shortcut to another file. |
FL::LOOP | In loop mode, the file object's position marker for read/write operations is allowed to extend past the actual file size. Any read/write operation beyond the file size will loop back to the file at a corrected offset - for example, reading position 330 of a 100 byte file will start the operation from the 30th byte. Loop mode does not affect any other area besides the read, write and seek operations. The loop feature is typically used to create multimedia data streams with minimal effort. |
FL::NEW | Required when creating a new file. If a file with the same name exists, its contents will be destroyed. If however the existing file is locked, the initalisation process will fail. |
FL::READ | Required if the file needs to be opened for read access. |
FL::RESET_DATE | For internal use only |
FL::STREAM | File data is streamed (e.g. PIPE, FIFO, socket) and may be accessed locally or via a network. |
FL::WRITE | Prepares a file for writing data, starting at byte position 0. To start writing from the end of a file, use the Seek action after the file has been initialised. |
Flags for the File Watch() method.
Name | Description |
---|---|
MFF::ATTRIB | File permissions or datestamp changed. |
MFF::CLOSED | An opened file has been closed. |
MFF::CREATE | New file/link created or renamed in folder. |
MFF::DEEP | Receive notifications from sub-folders (Windows only). |
MFF::DELETE | Existing file deleted |
MFF::FILE | File identifier; if passed to File⇒Watch() then indicates a preference for file events only. |
MFF::FOLDER | Folder identifier; if passed to File⇒Watch() then indicates a preference for folder events only. |
MFF::MODIFY | File modified via write or truncation. |
MFF::MOVED | Existing file moved or renamed. |
MFF::OPENED | Existing file was opened. |
MFF::READ | File was accessed (read). |
MFF::RENAME | Existing file moved or renamed. |
MFF::SELF | Event applies to the monitored folder and not a contained item |
MFF::UNMOUNT | Host filesystem was unmounted. |
MFF::WRITE | File modified via write or truncation. |
Permission flags
Name | Description |
---|---|
PERMIT::ALL_DELETE | Synonym for EVERYONE_DELETE |
PERMIT::ALL_EXEC | Synonym for EVERYONE_EXEC |
PERMIT::ALL_READ | Synonym for EVERYONE_READ |
PERMIT::ALL_WRITE | Synonym for EVERYONE_WRITE |
PERMIT::ARCHIVE | Marks the file for future backup. The flag should be cleared after the backup has succeeded. |
PERMIT::DELETE | Owner can delete. If the file system does not support this, deletion is enabled via the WRITE flag. |
PERMIT::EVERYONE_ACCESS | Synonym for EVERYONE_READ | EVERYONE_WRITE | EVERYONE_EXEC | EVERYONE_DELETE |
PERMIT::EVERYONE_DELETE | Synonym for DELETE | GROUP_DELETE | OTHERS_DELETE |
PERMIT::EVERYONE_EXEC | Synonym for EXEC | GROUP_EXEC | OTHERS_EXEC |
PERMIT::EVERYONE_READ | Synonym for READ | GROUP_READ | OTHERS_READ |
PERMIT::EVERYONE_READWRITE | Synonym for EVERYONE_READ | EVERYONE_WRITE |
PERMIT::EVERYONE_WRITE | Synonym for WRITE | GROUP_WRITE | OTHERS_WRITE |
PERMIT::EXEC | User/Owner can execute. |
PERMIT::GROUP | Synonym for GROUP_READ | GROUP_WRITE | GROUP_EXEC | GROUP_DELETE |
PERMIT::GROUPID | Allows executables to run with a set group id. |
PERMIT::GROUP_DELETE | Group members can delete. |
PERMIT::GROUP_EXEC | Group members can execute. |
PERMIT::GROUP_READ | Group members can read. |
PERMIT::GROUP_WRITE | Group members can write. |
PERMIT::HIDDEN | Recommends that the file is hidden from view by default. |
PERMIT::INHERIT | Inherit permissions from parent folder and logical OR them with preset permission flags. |
PERMIT::NETWORK | File is hosted on another machine. |
PERMIT::OFFLINE | File content for this networked file has not been cached on the local PC. |
PERMIT::OTHERS | Synonym for OTHERS_READ | OTHERS_WRITE | OTHERS_EXEC | OTHERS_DELETE |
PERMIT::OTHERS_DELETE | Others can delete. |
PERMIT::OTHERS_EXEC | Others can execute. |
PERMIT::OTHERS_READ | Others can read. |
PERMIT::OTHERS_WRITE | Others can write. |
PERMIT::PASSWORD | File is password protected. |
PERMIT::READ | User/Owner has read access. This will not allow compiled code to be executed. |
PERMIT::USER | Synonym for READ | WRITE | EXEC | DELETE |
PERMIT::USERID | Allows executables to run with a set user id. |
PERMIT::USER_EXEC | Synonym for EXEC |
PERMIT::USER_READ | Synonym for READ |
PERMIT::USER_WRITE | Synonym for WRITE |
PERMIT::WRITE | User/Owner can write. |
Generic structure for date-time management.
Field | Type | Description |
---|---|---|
Year | WORD | Year |
Month | BYTE | Month 1 to 12 |
Day | BYTE | Day 1 to 31 |
Hour | BYTE | Hour 0 to 23 |
Minute | BYTE | Minute 0 to 59 |
Second | BYTE | Second 0 to 59 |
TimeZone | BYTE | TimeZone -13 to +13 |
Class Info | |
---|---|
ID | ID_FILE |
Category | System |
Include | modules/file.h |
Version | 1.2 |