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