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