File


Object Hierarchy:

Object hierarchy for File

Description:

public interface File : Object

File is a high level abstraction for manipulating files on a virtual file system.

Files are lightweight, immutable objects that do no I/O upon creation. It is necessary to understand that File objects do not represent files, merely an identifier for a file. All file content I/O is implemented as streaming operations (see InputStream and OutputStream).

To construct a File, you can use: - new_for_path if you have a path. - new_for_uri if you have a URI. - new_for_commandline_arg for a command line argument. - new_tmp to create a temporary file from a template. - parse_name from a UTF-8 string gotten from get_parse_name.

One way to think of a File is as an abstraction of a pathname. For normal files the system pathname is what is stored internally, but as Files are extensible it could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.

Files make up hierarchies of directories and files that correspond to the files on a filesystem. You can move through the file system with File using get_parent to get an identifier for the parent directory, get_child to get a child within a directory, resolve_relative_path to resolve a relative path between two Files. There can be multiple hierarchies, so you may not end up at the same root if you repeatedly call get_parent on two different files.

All Files have a basename (get with get_basename). These names are byte strings that are used to identify the file on the filesystem (relative to its parent directory) and there is no guarantees that they have any particular charset encoding or even make any sense at all. If you want to use filenames in a user interface you should use the display name that you can get by requesting the g_file_attribute_standard_display_name attribute with query_info. This is guaranteed to be in UTF-8 and can be used in a user interface. But always store the real basename or the File to use to actually access the file, because there is no way to go from a display name to the actual name.

Using File as an identifier has the same weaknesses as using a path in that there may be multiple aliases for the same file. For instance, hard or soft links may cause two different Files to refer to the same file. Other possible causes for aliases are: case insensitive filesystems, short and long names on FAT/NTFS, or bind mounts in Linux. If you want to check if two Files point to the same file you can query for the g_file_attribute_id_file attribute. Note that File does some trivial canonicalization of pathnames passed in, so that trivial differences in the path string used at creation (duplicated slashes, slash at end of path, "." or ".." path segments, etc) does not create different Files.

Many File operations have both synchronous and asynchronous versions to suit your application. Asynchronous versions of synchronous functions simply have _async appended to their function names. The asynchronous I/O functions call a AsyncReadyCallback which is then used to finalize the operation, producing a GAsyncResult which is then passed to the function's matching _finish operation.

Some File operations do not have synchronous analogs, as they may take a very long time to finish, and blocking may leave an application unusable. Notable cases include: - mount_mountable to mount a mountable file. - unmount_mountable_with_operation to unmount a mountable file. - eject_mountable_with_operation to eject a mountable file.

Entity Tags # {gfile-etag}

One notable feature of Files are entity tags, or "etags" for short. Entity tags are somewhat like a more abstract version of the traditional mtime, and can be used to quickly determine if the file has been modified from the version on the file system. See the HTTP 1.1 specification for HTTP Etag headers, which are a very similar concept.


Namespace: GLib
Package: gio-2.0

Content:

Static methods:

Methods:

Inherited Members: