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,2002 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.51 2002/01/18 22:42:52 jeroen Exp $                         *
00023 ********************************************************************************/
00024 #ifndef FXFILE_H
00025 #define FXFILE_H
00026 
00027 
00028 /// Options for listing files
00029 enum {
00030   LIST_MATCHING_FILES = 0,              /// Matching files
00031   LIST_MATCHING_DIRS  = 0,              /// Matching directories
00032   LIST_NO_FILES       = 1,              /// Don't list any files
00033   LIST_NO_DIRS        = 2,              /// Don't list any directories
00034   LIST_ALL_FILES      = 4,              /// List all files
00035   LIST_ALL_DIRS       = 8,              /// List all directories
00036   LIST_HIDDEN_FILES   = 16,             /// List hidden files also
00037   LIST_HIDDEN_DIRS    = 32,             /// List hidden directories also
00038   LIST_NO_PARENT      = 64,             /// Don't include '..' in the listing
00039   LIST_CASEFOLD       = 128             /// Matching is case-insensitive
00040   };
00041 
00042 
00043 /// Declared as "C" so as to not clash tag-names
00044 extern "C" { struct stat; }
00045 
00046 
00047 namespace FXFile {
00048 
00049 /// Return value of environment variable name
00050 FXString FXAPI getEnvironment(const FXString& name);
00051 
00052 /// Return the home directory for the current user.
00053 FXString FXAPI getHomeDirectory();
00054 
00055 /// Return the home directory for a given user.
00056 FXString FXAPI getUserDirectory(const FXString& user);
00057 
00058 /// Set the current working directory
00059 FXbool FXAPI setCurrentDirectory(const FXString& path);
00060 
00061 /// Get the current working directory
00062 FXString FXAPI getCurrentDirectory();
00063 
00064 /// Set the current drive (for Win32 systems)
00065 FXbool FXAPI setCurrentDrive(const FXString& prefix);
00066 
00067 /// Return the current drive (for Win32 systems)
00068 FXString FXAPI getCurrentDrive();
00069 
00070 /// Get executable path
00071 FXString FXAPI getExecPath();
00072 
00073 /**
00074 * Return the directory part of the path name.
00075 * Note that directory("/bla/bla/") is "/bla/bla" and NOT "/bla".
00076 * However, directory("/bla/bla") is "/bla" as we expect!
00077 */
00078 FXString FXAPI directory(const FXString& file);
00079 
00080 /**
00081 * Return name and extension part of the path name.
00082 * Note that name("/bla/bla/") is "" and NOT "bla".
00083 * However, name("/bla/bla") is "bla" as we expect!
00084 */
00085 FXString FXAPI name(const FXString& file);
00086 
00087 /// Return file title, i.e. document name only
00088 FXString FXAPI title(const FXString& file);
00089 
00090 /// Return extension part of the file name
00091 FXString FXAPI extension(const FXString& file);
00092 
00093 /// Return file name less the extension
00094 FXString FXAPI stripExtension(const FXString& file);
00095 
00096 /// Return the drive letter prefixing this file name (if any).
00097 FXString FXAPI drive(const FXString& file);
00098 
00099 /// Perform tilde or environment variable expansion
00100 FXString FXAPI expand(const FXString& file);
00101 
00102 /**
00103 * Simplify a file path; the path will remain relative if it was relative,
00104 * or absolute if it was absolute.  Also, a trailing "/" will be preserved
00105 * as this is important in other functions.
00106 * For example, simplify("..//aaa/./bbb//../c/") becomes "../aaa/c/".
00107 */
00108 FXString FXAPI simplify(const FXString& file);
00109 
00110 /// Return absolute path from current directory and file name
00111 FXString FXAPI absolute(const FXString& file);
00112 
00113 /// Return absolute path from base directory and file name
00114 FXString FXAPI absolute(const FXString& base,const FXString& file);
00115 
00116 /// Return relative path of file to the current directory
00117 FXString FXAPI relative(const FXString& file);
00118 
00119 /// Return relative path of file to given base directory
00120 FXString FXAPI relative(const FXString& base,const FXString& file);
00121 
00122 /// Enquote filename to make safe for shell
00123 FXString FXAPI enquote(const FXString& file,FXbool forcequotes=FALSE);
00124 
00125 /// Dequote filename to get original again
00126 FXString FXAPI dequote(const FXString& file);
00127 
00128 /**
00129 * Generate unique filename of the form pathnameXXX.ext, where
00130 * pathname.ext is the original input file, and XXX is a number,
00131 * possibly empty, that makes the file unique.
00132 */
00133 FXString FXAPI unique(const FXString& file);
00134 
00135 /// Search path list for this file, return full path name for first occurrence
00136 FXString FXAPI search(const FXString& pathlist,const FXString& file);
00137 
00138 /// Return path to directory above input directory name
00139 FXString FXAPI upLevel(const FXString& file);
00140 
00141 /// Return true if file name is absolute
00142 FXbool FXAPI isAbsolute(const FXString& file);
00143 
00144 /// Return true if input directory is a top-level directory
00145 FXbool FXAPI isTopDirectory(const FXString& file);
00146 
00147 /// Return true if input path is a file name
00148 FXbool FXAPI isFile(const FXString& file);
00149 
00150 /// Return true if input path is a link
00151 FXbool FXAPI isLink(const FXString& file);
00152 
00153 /// Return true if input path is a directory
00154 FXbool FXAPI isDirectory(const FXString& file);
00155 
00156 /// Return true if file is readable
00157 FXbool FXAPI isReadable(const FXString& file);
00158 
00159 /// Return true if file is writable
00160 FXbool FXAPI isWritable(const FXString& file);
00161 
00162 /// Return true if file is executable
00163 FXbool FXAPI isExecutable(const FXString& file);
00164 
00165 /// Return true if owner has read-write-execute permissions
00166 FXbool FXAPI isOwnerReadWriteExecute(const FXString& file);
00167 
00168 /// Return true if owner has read permissions
00169 FXbool FXAPI isOwnerReadable(const FXString& file);
00170 
00171 /// Return true if owner has write permissions
00172 FXbool FXAPI isOwnerWritable(const FXString& file);
00173 
00174 /// Return true if owner has execute permissions
00175 FXbool FXAPI isOwnerExecutable(const FXString& file);
00176 
00177 /// Return true if group has read-write-execute permissions
00178 FXbool FXAPI isGroupReadWriteExecute(const FXString& file);
00179 
00180 /// Return true if group has read permissions
00181 FXbool FXAPI isGroupReadable(const FXString& file);
00182 
00183 /// Return true if group has write permissions
00184 FXbool FXAPI isGroupWritable(const FXString& file);
00185 
00186 /// Return true if group has execute permissions
00187 FXbool FXAPI isGroupExecutable(const FXString& file);
00188 
00189 /// Return true if others have read-write-execute permissions
00190 FXbool FXAPI isOtherReadWriteExecute(const FXString& file);
00191 
00192 /// Return true if others have read permissions
00193 FXbool FXAPI isOtherReadable(const FXString& file);
00194 
00195 /// Return true if others have write permissions
00196 FXbool FXAPI isOtherWritable(const FXString& file);
00197 
00198 /// Return true if others have execute permissions
00199 FXbool FXAPI isOtherExecutable(const FXString& file);
00200 
00201 /// Return true if the file sets the user id on execution
00202 FXbool FXAPI isSetUid(const FXString& file);
00203 
00204 /// Return true if the file sets the group id on execution
00205 FXbool FXAPI isSetGid(const FXString& file);
00206 
00207 /// Return true if the file has the sticky bit set
00208 FXbool FXAPI isSetSticky(const FXString& file);
00209 
00210 /// Return owner name of file (if available, else "user")
00211 FXString FXAPI owner(const FXString& file);
00212 
00213 /// Return group name of file (if available, else "group")
00214 FXString FXAPI group(const FXString& file);
00215 
00216 /// Return file size in bytes
00217 unsigned long FXAPI size(const FXString& file);
00218 
00219 /// Return last modified time for this file
00220 FXTime FXAPI modified(const FXString& file);
00221 
00222 /// Return last accessed time for this file
00223 FXTime FXAPI accessed(const FXString& file);
00224 
00225 /// Return created time for this file
00226 FXTime FXAPI created(const FXString& file);
00227 
00228 /// Return touched time for this file
00229 FXTime FXAPI touched(const FXString& file);
00230 
00231 /// Match filenames using *, ?, [^a-z], and so on
00232 FXbool FXAPI match(const FXString& pattern,const FXString& file,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME));
00233 
00234 /**
00235 * List files in a given directory.
00236 * Returns the number of files in the string-array list which matched the
00237 * pattern or satisfied the flag conditions.
00238 */
00239 FXint FXAPI listFiles(FXString*& list,const FXString& path,const FXString& pattern="*",FXuint flags=LIST_MATCHING_FILES|LIST_MATCHING_DIRS);
00240 
00241 /// Return current time
00242 FXTime FXAPI now();
00243 
00244 /// Convert file time to date-string
00245 FXString FXAPI time(FXTime filetime);
00246 
00247 /**
00248 * Convert file time to date-string as per strftime.
00249 * Format characters supported by most systems are:
00250 *
00251 *  %a %A %b %B %c %d %H %I %j %m %M %p %S %U %w %W %x %X %y %Y %Z %%
00252 *
00253 * Some systems support additional conversions.
00254 */
00255 FXString FXAPI time(const FXchar *format,FXTime filetime);
00256 
00257 /// Return file info as reported by system stat() function
00258 FXbool FXAPI info(const FXString& file,struct stat& info);
00259 
00260 /// Return true if file exists
00261 FXbool FXAPI exists(const FXString& file);
00262 
00263 /// Return true if files are identical
00264 FXbool FXAPI identical(const FXString& file1,const FXString& file2);
00265 
00266 /// Return the mode flags for this file
00267 FXuint FXAPI mode(const FXString& file);
00268 
00269 /// Change the mode flags for this file
00270 FXbool FXAPI mode(const FXString& file,FXuint mode);
00271 
00272 /// Create new directory
00273 FXbool FXAPI createDirectory(const FXString& path,FXuint mode);
00274 
00275 /// Create new (empty) file
00276 FXbool FXAPI createFile(const FXString& file,FXuint mode);
00277 
00278 /**
00279 * Concatenate srcfile1 and srcfile2 to a dstfile.
00280 * If overwrite is true, then the operation fails if dstfile already exists.
00281 * srcfile1 and srcfile2 should not be the same as dstfile.
00282 */
00283 FXbool FXAPI concatenate(const FXString& srcfile1,const FXString& srcfile2,const FXString& dstfile,FXbool overwrite=FALSE);
00284 
00285 /// Remove file or directory, recursively.
00286 FXbool FXAPI remove(const FXString& file);
00287 
00288 /// Copy file or directory, recursively
00289 FXbool FXAPI copy(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00290 
00291 /// Rename or move file or directory
00292 FXbool FXAPI move(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00293 
00294 /// Link file
00295 FXbool FXAPI link(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00296 
00297 /// Symbolic link file
00298 FXbool FXAPI symlink(const FXString& srcfile,const FXString& dstfile,FXbool overwrite=FALSE);
00299 
00300 /// Read symbolic link
00301 FXString FXAPI symlink(const FXString& file);
00302 
00303 }
00304 
00305 #endif