Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXFile.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *      F i l e   I n f o r m a t i o n   a n d   M a n i p u l a t i o n        *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2000,2004 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXFile.h,v 1.65 2004/02/08 17:17:33 fox Exp $                            *
00023 ********************************************************************************/
00024 #ifndef FXFILE_H
00025 #define FXFILE_H
00026 
00027 
00028 /// Declared as "C" so as to not clash tag-names
00029 extern "C" { struct stat; }
00030 
00031 namespace FX {
00032 
00033 
00034 /// Options for listing files
00035 enum {
00036   LIST_MATCH_ALL      = 0,              /// Matching files and directories
00037   LIST_NO_FILES       = 1,              /// Don't list any files
00038   LIST_NO_DIRS        = 2,              /// Don't list any directories
00039   LIST_ALL_FILES      = 4,              /// List all files
00040   LIST_ALL_DIRS       = 8,              /// List all directories
00041   LIST_HIDDEN_FILES   = 16,             /// List hidden files also
00042   LIST_HIDDEN_DIRS    = 32,             /// List hidden directories also
00043   LIST_NO_PARENT      = 64,             /// Don't include '..' in the listing
00044   LIST_CASEFOLD       = 128             /// Matching is case-insensitive
00045   };
00046 
00047 
00048 namespace FXFile {      // FIXME do we still need FXFile namespace at all?
00049 
00050 
00051 /// Return value of environment variable name
00052 FXString FXAPI getEnvironment(const FXString& name);
00053 
00054 /// Return the home directory for the current user.
00055 FXString FXAPI getHomeDirectory();
00056 
00057 /// Return the home directory for a given user.
00058 FXString FXAPI getUserDirectory(const FXString& user);
00059 
00060 /// Return temporary directory.
00061 FXString FXAPI getTempDirectory();
00062 
00063 /// Set the current working directory
00064 FXbool FXAPI setCurrentDirectory(const FXString& path);
00065 
00066 /// Get the current working directory
00067 FXString FXAPI getCurrentDirectory();
00068 
00069 /// Set the current drive (for Win32 systems)
00070 FXbool FXAPI setCurrentDrive(const FXString& prefix);
00071 
00072 /// Return the current drive (for Win32 systems)
00073 FXString FXAPI getCurrentDrive();
00074 
00075 /// Get executable path
00076 FXString FXAPI getExecPath();
00077 
00078 /**
00079 * Return the directory part of the path name.
00080 * Note that directory("/bla/bla/") is "/bla/bla" and NOT "/bla".
00081 * However, directory("/bla/bla") is "/bla" as we expect!
00082 */
00083 FXString FXAPI directory(const FXString& file);
00084 
00085 /**
00086 * Return name and extension part of the path name.
00087 * Note that name("/bla/bla/") is "" and NOT "bla".
00088 * However, name("/bla/bla") is "bla" as we expect!
00089 */
00090 FXString FXAPI name(const FXString& file);
00091 
00092 /// Return file title, i.e. document name only
00093 FXString FXAPI title(const FXString& file);
00094 
00095 /// Return extension part of the file name
00096 FXString FXAPI extension(const FXString& file);
00097 
00098 /// Return file name less the extension
00099 FXString FXAPI stripExtension(const FXString& file);
00100 
00101 /// Return the drive letter prefixing this file name (if any).
00102 FXString FXAPI drive(const FXString& file);
00103 
00104 /// Perform tilde or environment variable expansion
00105 FXString FXAPI expand(const FXString& file);
00106 
00107 /**
00108 * Simplify a file path; the path will remain relative if it was relative,
00109 * or absolute if it was absolute.  Also, a trailing "/" will be preserved
00110 * as this is important in other functions.
00111 * For example, simplify("..//aaa/./bbb//../c/") becomes "../aaa/c/".
00112 */
00113 FXString FXAPI simplify(const FXString& file);
00114 
00115 /// Return absolute path from current directory and file name
00116 FXString FXAPI absolute(const FXString& file);
00117 
00118 /// Return absolute path from base directory and file name
00119 FXString FXAPI absolute(const FXString& base,const FXString& file);
00120 
00121 /// Return relative path of file to the current directory
00122 FXString FXAPI relative(const FXString& file);
00123 
00124 /// Return relative path of file to given base directory
00125 FXString FXAPI relative(const FXString& base,const FXString& file);
00126 
00127 /**
00128 * Return root of absolute path; on Unix, this is just "/". On
00129 * Windows, this is "\\" or "C:\".  Returns the empty string
00130 * if the given path is not absolute.
00131 */
00132 FXString FXAPI root(const FXString& file);
00133 
00134 /// Enquote filename to make safe for shell
00135 FXString FXAPI enquote(const FXString& file,FXbool forcequotes=FALSE);
00136 
00137 /// Dequote filename to get original again
00138 FXString FXAPI dequote(const FXString& file);
00139 
00140 /**
00141 * Generate unique filename of the form pathnameXXX.ext, where
00142 * pathname.ext is the original input file, and XXX is a number,
00143 * possibly empty, that makes the file unique.
00144 */
00145 FXString FXAPI unique(const FXString& file);
00146 
00147 /// Search path list for this file, return full path name for first occurrence
00148 FXString FXAPI search(const FXString& pathlist,const FXString& file);
00149 
00150 /// Return path to directory above input directory name
00151 FXString FXAPI upLevel(const FXString& file);
00152 
00153 /// Return true if file name is absolute
00154 FXbool FXAPI isAbsolute(const FXString& file);
00155 
00156 /// Return true if input directory is a top-level directory
00157 FXbool FXAPI isTopDirectory(const FXString& file);
00158 
00159 /// Return true if input path is a file name
00160 FXbool FXAPI isFile(const FXString& file);
00161 
00162 /// Return true if input path is a link
00163 FXbool FXAPI isLink(const FXString& file);
00164 
00165 /// Return true if input path is a directory
00166 FXbool FXAPI isDirectory(const FXString& file);
00167 
00168 /// Return true if input path is a file share
00169 FXbool FXAPI isShare(const FXString& file);
00170 
00171 /// Return true if file is readable
00172 FXbool FXAPI isReadable(const FXString& file);
00173 
00174 /// Return true if file is writable
00175 FXbool FXAPI isWritable(const FXString& file);
00176 
00177 /// Return true if file is executable
00178 FXbool FXAPI isExecutable(const FXString& file);
00179 
00180 /// Return true if owner has read-write-execute permissions
00181 FXbool FXAPI isOwnerReadWriteExecute(const FXString& file);
00182 
00183 /// Return true if owner has read permissions
00184 FXbool FXAPI isOwnerReadable(const FXString& file);
00185 
00186 /// Return true if owner has write permissions
00187 FXbool FXAPI isOwnerWritable(const FXString& file);
00188 
00189 /// Return true if owner has execute permissions
00190 FXbool FXAPI isOwnerExecutable(const FXString& file);
00191 
00192 /// Return true if group has read-write-execute permissions
00193 FXbool FXAPI isGroupReadWriteExecute(const FXString& file);
00194 
00195 /// Return true if group has read permissions
00196 FXbool FXAPI isGroupReadable(const FXString& file);
00197 
00198 /// Return true if group has write permissions
00199 FXbool FXAPI isGroupWritable(const FXString& file);
00200 
00201 /// Return true if group has execute permissions
00202 FXbool FXAPI isGroupExecutable(const FXString& file);
00203 
00204 /// Return true if others have read-write-execute permissions
00205 FXbool FXAPI isOtherReadWriteExecute(const FXString& file);
00206 
00207 /// Return true if others have read permissions
00208 FXbool FXAPI isOtherReadable(const FXString& file);
00209 
00210 /// Return true if others have write permissions
00211 FXbool FXAPI isOtherWritable(const FXString& file);
00212 
00213 /// Return true if others have execute permissions
00214 FXbool FXAPI isOtherExecutable(const FXString& file);
00215 
00216 /// Return true if the file sets the user id on execution
00217 FXbool FXAPI isSetUid(const FXString& file);
00218 
00219 /// Return true if the file sets the group id on execution
00220 FXbool FXAPI isSetGid(const FXString& file);
00221 
00222 /// Return true if the file has the sticky bit set
00223 FXbool FXAPI isSetSticky(const FXString& file);
00224 
00225 /// Return owner name from uid if available
00226 FXString FXAPI owner(FXuint uid);
00227 
00228 /// Return owner name of file if available
00229 FXString FXAPI owner(const FXString& file);
00230 
00231 /// Return group name from gid if available
00232 FXString FXAPI group(FXuint gid);
00233 
00234 /// Return group name of file if available
00235 FXString FXAPI group(const FXString& file);
00236 
00237 /// Return permissions string
00238 FXString FXAPI permissions(FXuint mode);
00239 
00240 /// Return file size in bytes
00241 unsigned long FXAPI size(const FXString& file);
00242 
00243 /**
00244 * Return last modified time for this file, on filesystems
00245 * where this is supported.  This is the time when any data
00246 * in the file was last modified.
00247 */
00248 FXTime FXAPI modified(const FXString& file);
00249 
00250 /**
00251 * Return last accessed time for this file, on filesystems
00252 * where this is supported.
00253 */
00254 FXTime FXAPI accessed(const FXString& file);
00255 
00256 /**
00257 * Return created time for this file, on filesystems
00258 * where this is supported.  This is also the time when
00259 * ownership, permissions, links, and other meta-data may
00260 * have changed.
00261 */
00262 FXTime FXAPI created(const FXString& file);
00263 
00264 /**
00265 * Return touched time for this file, on filesystems
00266 * where this is supported.  This is the time when anything
00267 * at all, either contents or meta-data, about the file was
00268 * changed.
00269 */
00270 FXTime FXAPI touched(const FXString& file);
00271 
00272 /// Match filenames using *, ?, [^a-z], and so on
00273 FXbool FXAPI match(const FXString& pattern,const FXString& file,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME));
00274 
00275 /**
00276 * List files in a given directory.
00277 * Returns the number of files in the string-array list which matched the
00278 * pattern or satisfied the flag conditions.
00279 */
00280 FXint FXAPI listFiles(FXString*& filelist,const FXString& path,const FXString& pattern="*",FXuint flags=LIST_MATCH_ALL);
00281 
00282 /// Return current time
00283 FXTime FXAPI now();
00284 
00285 /// Convert file time to date-string
00286 FXString FXAPI time(FXTime filetime);
00287 
00288 /**
00289 * Convert file time to date-string as per strftime.
00290 * Format characters supported by most systems are:
00291 *
00292 *  %a %A %b %B %c %d %H %I %j %m %M %p %S %U %w %W %x %X %y %Y %Z %%
00293 *
00294 * Some systems support additional conversions.
00295 */
00296 FXString FXAPI time(const FXchar *format,FXTime filetime);
00297 
00298 /// Return file info as reported by system stat() function
00299 FXbool FXAPI info(const FXString& file,struct stat& inf);
00300 
00301 /// Return file info as reported by system lstat() function
00302 FXbool FXAPI linkinfo(const FXString& file,struct stat& inf);
00303 
00304 /// Return true if file exists
00305 FXbool FXAPI exists(const FXString& file);
00306 
00307 /// Return true if files are identical
00308 FXbool FXAPI identical(const FXString& file1,const FXString& file2);
00309 
00310 /// Return the mode flags for this file
00311 FXuint FXAPI mode(const FXString& file);
00312 
00313 /// Change the mode flags for this file
00314 FXbool FXAPI mode(const FXString& file,FXuint mode);
00315 
00316 /// Create new directory
00317 FXbool FXAPI createDirectory(const FXString& path,FXuint mode);
00318 
00319 /// Create new (empty) file
00320 FXbool FXAPI createFile(const FXString& file,FXuint mode);
00321 
00322 /**
00323 * Concatenate srcfile1 and srcfile2 to a dstfile.
00324 * If overwrite is true, then the operation fails if dstfile already exists.
00325 * srcfile1 and srcfile2 should not be the same as dstfile.
00326 */
00327 FXbool FXAPI concatenate(const FXString& srcfile1,const FXString& srcfile2,const FXString& dstfile,FXbool overwrite=FALSE);
00328 
00329 /// Remove file or directory, recursively.
00330 FXbool FXAPI remove(const FXString& file);
00331 
00332 /// Copy file or directory, recursively
00333 FXbool FXAPI copy(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00334 
00335 /// Rename or move file or directory
00336 FXbool FXAPI move(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00337 
00338 /// Link file
00339 FXbool FXAPI link(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00340 
00341 /// Symbolic link file
00342 FXbool FXAPI symlink(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00343 
00344 /// Read symbolic link
00345 FXString FXAPI symlink(const FXString& file);
00346 
00347 }
00348 
00349 }
00350 
00351 #endif

Copyright © 1997-2004 Jeroen van der Zijp