00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef Foundation_File_INCLUDED
00040 #define Foundation_File_INCLUDED
00041
00042
00043 #include "Poco/Foundation.h"
00044 #include "Poco/Timestamp.h"
00045 #include <vector>
00046
00047
00048 #if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
00049 #include "Poco/File_WIN32U.h"
00050 #elif defined(POCO_OS_FAMILY_WINDOWS)
00051 #include "Poco/File_WIN32.h"
00052 #elif defined(POCO_OS_FAMILY_UNIX)
00053 #include "Poco/File_UNIX.h"
00054 #else
00055 #include "Poco/File_VMS.h"
00056 #endif
00057
00058
00059 namespace Poco {
00060
00061
00062 class Path;
00063
00064
00065 class Foundation_API File: private FileImpl
00067 {
00068 public:
00069 typedef FileSizeImpl FileSize;
00070
00071 File();
00073
00074 File(const std::string& path);
00076
00077 File(const char* path);
00079
00080 File(const Path& path);
00082
00083 File(const File& file);
00085
00086 virtual ~File();
00088
00089 File& operator = (const File& file);
00091
00092 File& operator = (const std::string& path);
00094
00095 File& operator = (const char* path);
00097
00098 File& operator = (const Path& path);
00100
00101 void swap(File& file);
00103
00104 const std::string& path() const;
00106
00107 bool exists() const;
00109
00110 bool canRead() const;
00112
00113 bool canWrite() const;
00115
00116 bool canExecute() const;
00123
00124 bool isFile() const;
00126
00127 bool isLink() const;
00129
00130 bool isDirectory() const;
00132
00133 bool isDevice() const;
00135
00136 bool isHidden() const;
00144
00145 Timestamp created() const;
00153
00154 Timestamp getLastModified() const;
00156
00157 void setLastModified(const Timestamp& ts);
00159
00160 FileSize getSize() const;
00162
00163 void setSize(FileSize size);
00166
00167 void setWriteable(bool flag = true);
00171
00172 void setReadOnly(bool flag = true);
00176
00177 void setExecutable(bool flag = true);
00183
00184 void copyTo(const std::string& path) const;
00189
00190 void moveTo(const std::string& path);
00193
00194 void renameTo(const std::string& path);
00196
00197 void remove(bool recursive = false);
00201
00202 bool createFile();
00207
00208 bool createDirectory();
00212
00213 void createDirectories();
00216
00217 void list(std::vector<std::string>& files) const;
00220
00221 void list(std::vector<File>& files) const;
00224
00225 bool operator == (const File& file) const;
00226 bool operator != (const File& file) const;
00227 bool operator < (const File& file) const;
00228 bool operator <= (const File& file) const;
00229 bool operator > (const File& file) const;
00230 bool operator >= (const File& file) const;
00231
00232 static void handleLastError(const std::string& path);
00235
00236 protected:
00237 void copyDirectory(const std::string& path) const;
00239 };
00240
00241
00242
00243
00244
00245 inline const std::string& File::path() const
00246 {
00247 return getPathImpl();
00248 }
00249
00250
00251 inline bool File::operator == (const File& file) const
00252 {
00253 return getPathImpl() == file.getPathImpl();
00254 }
00255
00256
00257 inline bool File::operator != (const File& file) const
00258 {
00259 return getPathImpl() != file.getPathImpl();
00260 }
00261
00262
00263 inline bool File::operator < (const File& file) const
00264 {
00265 return getPathImpl() < file.getPathImpl();
00266 }
00267
00268
00269 inline bool File::operator <= (const File& file) const
00270 {
00271 return getPathImpl() <= file.getPathImpl();
00272 }
00273
00274
00275 inline bool File::operator > (const File& file) const
00276 {
00277 return getPathImpl() > file.getPathImpl();
00278 }
00279
00280
00281 inline bool File::operator >= (const File& file) const
00282 {
00283 return getPathImpl() >= file.getPathImpl();
00284 }
00285
00286
00287 inline void swap(File& f1, File& f2)
00288 {
00289 f1.swap(f2);
00290 }
00291
00292
00293 }
00294
00295
00296 #endif // Foundation_File_INCLUDED