1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module glib.Directory; 26 27 private import glib.ErrorG; 28 private import glib.GException; 29 private import glib.Str; 30 private import gtkc.glib; 31 public import gtkc.glibtypes; 32 33 34 /** 35 * An opaque structure representing an opened directory. 36 */ 37 public class Directory 38 { 39 /** the main Gtk struct */ 40 protected GDir* gDir; 41 42 /** Get the main Gtk struct */ 43 public GDir* getDirectoryStruct() 44 { 45 return gDir; 46 } 47 48 /** the main Gtk struct as a void* */ 49 protected void* getStruct() 50 { 51 return cast(void*)gDir; 52 } 53 54 /** 55 * Sets our main struct and passes it to the parent class. 56 */ 57 public this (GDir* gDir) 58 { 59 this.gDir = gDir; 60 } 61 62 63 /** 64 * Closes the directory and deallocates all related resources. 65 */ 66 public void close() 67 { 68 g_dir_close(gDir); 69 } 70 71 /** 72 * Retrieves the name of another entry in the directory, or %NULL. 73 * The order of entries returned from this function is not defined, 74 * and may vary by file system or other operating-system dependent 75 * factors. 76 * 77 * %NULL may also be returned in case of errors. On Unix, you can 78 * check `errno` to find out if %NULL was returned because of an error. 79 * 80 * On Unix, the '.' and '..' entries are omitted, and the returned 81 * name is in the on-disk encoding. 82 * 83 * On Windows, as is true of all GLib functions which operate on 84 * filenames, the returned name is in UTF-8. 85 * 86 * Return: The entry's name or %NULL if there are no 87 * more entries. The return value is owned by GLib and 88 * must not be modified or freed. 89 */ 90 public string readName() 91 { 92 return Str.toString(g_dir_read_name(gDir)); 93 } 94 95 /** 96 * Resets the given directory. The next call to g_dir_read_name() 97 * will return the first entry again. 98 */ 99 public void rewind() 100 { 101 g_dir_rewind(gDir); 102 } 103 104 /** 105 * Creates a subdirectory in the preferred directory for temporary 106 * files (as returned by g_get_tmp_dir()). 107 * 108 * @tmpl should be a string in the GLib file name encoding containing 109 * a sequence of six 'X' characters, as the parameter to g_mkstemp(). 110 * However, unlike these functions, the template should only be a 111 * basename, no directory components are allowed. If template is 112 * %NULL, a default template is used. 113 * 114 * Note that in contrast to g_mkdtemp() (and mkdtemp()) @tmpl is not 115 * modified, and might thus be a read-only literal string. 116 * 117 * Params: 118 * tmpl = Template for directory name, 119 * as in g_mkdtemp(), basename only, or %NULL for a default template 120 * 121 * Return: The actual name used. This string 122 * should be freed with g_free() when not needed any longer and is 123 * is in the GLib file name encoding. In case of errors, %NULL is 124 * returned and @error will be set. 125 * 126 * Since: 2.30 127 * 128 * Throws: GException on failure. 129 */ 130 public static string makeTmp(string tmpl) 131 { 132 GError* err = null; 133 134 auto p = g_dir_make_tmp(Str.toStringz(tmpl), &err); 135 136 if (err !is null) 137 { 138 throw new GException( new ErrorG(err) ); 139 } 140 141 return Str.toString(p); 142 } 143 144 /** 145 * Opens a directory for reading. The names of the files in the 146 * directory can then be retrieved using g_dir_read_name(). Note 147 * that the ordering is not defined. 148 * 149 * Params: 150 * path = the path to the directory you are interested in. On Unix 151 * in the on-disk encoding. On Windows in UTF-8 152 * flags = Currently must be set to 0. Reserved for future use. 153 * 154 * Return: a newly allocated #GDir on success, %NULL on failure. 155 * If non-%NULL, you must free the result with g_dir_close() 156 * when you are finished with it. 157 * 158 * Throws: GException on failure. 159 */ 160 public static Directory open(string path, uint flags) 161 { 162 GError* err = null; 163 164 auto p = g_dir_open(Str.toStringz(path), flags, &err); 165 166 if (err !is null) 167 { 168 throw new GException( new ErrorG(err) ); 169 } 170 171 if(p is null) 172 { 173 return null; 174 } 175 176 return new Directory(cast(GDir*) p); 177 } 178 }