FileUtils

Description There is a group of functions which wrap the common POSIX functions dealing with filenames (g_open(), g_rename(), g_mkdir(), g_stat(), g_unlink(), g_remove(), g_fopen(), g_freopen()). The point of these wrappers is to make it possible to handle file names with any Unicode characters in them on Windows without having to use ifdefs and the wide character API in the application code. The pathname argument should be in the GLib file name encoding. On POSIX this is the actual on-disk encoding which might correspond to the locale settings of the process (or the G_FILENAME_ENCODING environment variable), or not. On Windows the GLib file name encoding is UTF-8. Note that the Microsoft C library does not use UTF-8, but has separate APIs for current system code page and wide characters (UTF-16). The GLib wrappers call the wide character API if present (on modern Windows systems), otherwise convert to/from the system code page. Another group of functions allows to open and read directories in the GLib file name encoding. These are g_dir_open(), g_dir_read_name(), g_dir_rewind(), g_dir_close().

Members

Static functions

access
int access(string filename, int mode)

A wrapper for the POSIX access() function. This function is used to test a pathname for one or several of read, write or execute permissions, or just existence. On Windows, the file protection mechanism is not at all POSIX-like, and the underlying function in the C library only checks the FAT-style READONLY attribute, and does not look at the ACL of a file at all. This function is this in practise almost useless on Windows. Software that needs to handle file permissions on Windows more exactly should use the Win32 API. See your C library manual for more details about access(). Since 2.8

chdir
int chdir(string path)

A wrapper for the POSIX chdir() function. The function changes the current directory of the process to path. See your C library manual for more details about chdir(). Since 2.8

fileErrorFromErrno
GFileError fileErrorFromErrno(int errNo)

Gets a GFileError constant based on the passed-in errno. For example, if you pass in EEXIST this function returns G_FILE_ERROR_EXIST. Unlike errno values, you can portably assume that all GFileError values will exist. Normally a GFileError value goes into a GError returned from a function that manipulates files. So you would use g_file_error_from_errno() when constructing a GError.

fileReadLink
string fileReadLink(string filename)

Reads the contents of the symbolic link filename like the POSIX readlink() function. The returned string is in the encoding used for filenames. Use g_filename_to_utf8() to convert it to UTF-8. Since 2.4

fileSetContents
int fileSetContents(string filename, string contents, gssize length)

Writes all of contents to a file named filename, with good error checking. If a file called filename already exists it will be overwritten. This write is atomic in the sense that it is first written to a temporary Since 2.8

mkdirWithParents
int mkdirWithParents(string pathname, int mode)

Create a directory if it doesn't already exist. Create intermediate parent directories as needed, too. Since 2.8

mkstempFull
int mkstempFull(string tmpl, int flags, int mode)

Opens a temporary file. See the mkstemp() documentation on most UNIX-like systems. The parameter is a string that should follow the rules for mkstemp() templates, i.e. contain the string "XXXXXX". g_mkstemp_full() is slightly more flexible than mkstemp() in that the sequence does not have to occur at the very end of the template and you can pass a mode and additional flags. The X string will be modified to form the name of a file that didn't exist. The string should be in the GLib file name encoding. Most importantly, on Windows it should be in UTF-8. Since 2.22

rmdir
int rmdir(string filename)

A wrapper for the POSIX rmdir() function. The rmdir() function deletes a directory from the filesystem. See your C library manual for more details about how rmdir() works on your system. Since 2.6

unlink
int unlink(string filename)

A wrapper for the POSIX unlink() function. The unlink() function deletes a name from the filesystem. If this was the last link to the file and no processes have it opened, the diskspace occupied by the file is freed. See your C library manual for more details about unlink(). Note that on Windows, it is in general not possible to delete files that are open to some process, or mapped into memory. Since 2.6

Meta