[]Struct gio::File

pub struct File(_, _);

File is a high level abstraction for manipulating files on a virtual file system. GFiles 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:

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 GFiles are extensible it could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.

GFiles 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 File::get_parent to get an identifier for the parent directory, File::get_child to get a child within a directory, File::resolve_relative_path to resolve a relative path between two GFiles. There can be multiple hierarchies, so you may not end up at the same root if you repeatedly call File::get_parent on two different files.

All GFiles have a basename (get with File::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 File::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 GFiles 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 GFiles 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 GFiles.

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 GAsyncReadyCallback which is then used to finalize the operation, producing a GAsyncResult which is then passed to the function's matching _finish operation.

It is highly recommended to use asynchronous calls when running within a shared main loop, such as in the main thread of an application. This avoids I/O operations blocking other sources on the main loop from being dispatched. Synchronous I/O operations should be performed from worker threads. See the [introduction to asynchronous programming section][async-programming] for more.

Some File operations almost always take a noticeable amount of time, and so do not have synchronous analogs. Notable cases include:

Entity Tags # {gfile-etag}

One notable feature of GFiles 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.

Implements

FileExt, FileExtManual

Implementations

impl File[src]

pub fn new_for_commandline_arg<P: AsRef<OsStr>>(arg: P) -> File[src]

Creates a File with the given argument from the command line. The value of arg can be either a URI, an absolute path or a relative path resolved relative to the current working directory. This operation never fails, but the returned object might not support any I/O operation if arg points to a malformed path.

Note that on Windows, this function expects its argument to be in UTF-8 -- not the system code page. This means that you should not use this function with string from argv as it is passed to main. g_win32_get_command_line will return a UTF-8 version of the commandline. Application also uses UTF-8 but ApplicationCommandLineExt::create_file_for_arg may be more useful for you there. It is also always possible to use this function with glib::OptionContext arguments of type glib::OptionArg::Filename.

arg

a command line string

Returns

a new File. Free the returned object with gobject::ObjectExt::unref.

pub fn new_for_commandline_arg_and_cwd<P: AsRef<OsStr>, Q: AsRef<Path>>(
    arg: P,
    cwd: Q
) -> File
[src]

Creates a File with the given argument from the command line.

This function is similar to File::new_for_commandline_arg except that it allows for passing the current working directory as an argument instead of using the current working directory of the process.

This is useful if the commandline argument was given in a context other than the invocation of the current process.

See also ApplicationCommandLineExt::create_file_for_arg.

arg

a command line string

cwd

the current working directory of the commandline

Returns

a new File

pub fn new_for_path<P: AsRef<Path>>(path: P) -> File[src]

Constructs a File for a given path. This operation never fails, but the returned object might not support any I/O operation if path is malformed.

path

a string containing a relative or absolute path. The string must be encoded in the glib filename encoding.

Returns

a new File for the given path. Free the returned object with gobject::ObjectExt::unref.

pub fn new_for_uri(uri: &str) -> File[src]

Constructs a File for a given URI. This operation never fails, but the returned object might not support any I/O operation if uri is malformed or if the uri type is not supported.

uri

a UTF-8 string containing a URI

Returns

a new File for the given uri. Free the returned object with gobject::ObjectExt::unref.

pub fn new_tmp<P: AsRef<Path>>(tmpl: P) -> Result<(File, FileIOStream), Error>[src]

Opens a file in the preferred directory for temporary files (as returned by g_get_tmp_dir) and returns a File and FileIOStream pointing to it.

tmpl should be a string in the GLib file name encoding containing a sequence of six 'X' characters, and containing no directory components. If it is None, a default template is used.

Unlike the other File constructors, this will return None if a temporary file could not be created.

tmpl

Template for the file name, as in g_file_open_tmp, or None for a default template

iostream

on return, a FileIOStream for the created file

Returns

a new File. Free the returned object with gobject::ObjectExt::unref.

pub fn parse_name(parse_name: &str) -> Option<File>[src]

Constructs a File with the given parse_name (i.e. something given by File::get_parse_name). This operation never fails, but the returned object might not support any I/O operation if the parse_name cannot be parsed.

parse_name

a file name or path to be parsed

Returns

a new File.

Trait Implementations

impl Clone for File

impl Debug for File

impl Display for File[src]

impl Eq for File

impl Hash for File

impl Ord for File

impl<T: ObjectType> PartialEq<T> for File

impl<T: ObjectType> PartialOrd<T> for File

impl Send for File[src]

impl StaticType for File

impl Sync for File[src]

Auto Trait Implementations

impl RefUnwindSafe for File

impl Unpin for File

impl UnwindSafe for File

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.