00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_SYSTEM_DIRECTORY_H
00008 #define BALL_SYSTEM_DIRECTORY_H
00009
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013
00014 #ifndef BALL_CONCEPT_PROCESSOR_H
00015 # include <BALL/CONCEPT/processor.h>
00016 #endif
00017
00018 #ifndef BALL_DATATYPE_STRING_H
00019 # include <BALL/DATATYPE/string.h>
00020 #endif
00021
00022 #ifndef BALL_SYSTEM_FILESYSTEM_H
00023 # include <BALL/SYSTEM/fileSystem.h>
00024 #endif
00025
00026 #ifdef BALL_HAS_DIRENT_H
00027 # include <dirent.h>
00028 #endif
00029 #ifdef BALL_HAS_UNISTD_H
00030 # include <unistd.h>
00031 #endif
00032 #ifdef BALL_HAS_SYS_STAT_H
00033 # include <sys/stat.h>
00034 #endif
00035 #ifdef BALL_HAS_DIRECT_H
00036 # include <direct.h>
00037 #endif
00038 #include <stdio.h>
00039 #ifdef BALL_COMPILER_MSVC
00040 #define WINDOWS_LEAN_AND_MEAN
00041 #include <windows.h>
00042 #endif
00043
00044 namespace BALL
00045 {
00049 class BALL_EXPORT Directory
00050 {
00051 #ifndef BALL_PLATFORM_WINDOWS
00052 # define INVALID_HANDLE_VALUE 0
00053 #endif
00054
00055 public:
00056
00060
00065 static const Size MAX_PATH_LENGTH;
00066
00068
00071
00078 Directory();
00079
00088 Directory(const String& directory_path, bool set_current = false);
00089
00095 Directory(const Directory& directory);
00096
00099 ~Directory();
00100
00105 void clear();
00106
00109 void destroy();
00110
00112
00115
00123 bool set(const String& directory_path, bool set_current = false);
00124
00129 void set(const Directory& directory);
00130
00134 Directory& operator = (const Directory& directory);
00135
00140 void get(Directory& directory) const;
00142
00146
00152 const String& getPath() const;
00153
00161 bool rename(String old_path, String new_path);
00162
00167 bool renameTo(String new_path);
00168
00173 bool setCurrent(String directory_path);
00174
00178 bool setCurrent();
00179
00187 bool create(String path, const mode_t& mode = 0777);
00188
00195 bool remove(String old_path);
00196
00201 bool remove();
00202
00207 bool getFirstEntry(String& entry);
00208
00213 bool getNextEntry(String& entry);
00214
00218 Size countItems();
00219
00223 Size countFiles();
00224
00228 Size countDirectories();
00229
00236 bool find(const String& filename, String& filepath);
00237
00239
00242
00247 bool has(const String& item);
00248
00254 bool isValid() const;
00255
00259 bool isCurrent() const;
00260
00264 bool isEmpty();
00265
00269 bool operator == (const Directory& directory) const;
00270
00274 bool operator != (const Directory& directory) const;
00275
00277 static String getUserHomeDir();
00278
00280 static bool changeToUserHomeDir();
00281
00283
00284 private:
00285
00286
00287 String getcwd_();
00288
00289
00290 int chdir_(const String& new_dir);
00291
00292
00293 void synchronize_();
00294
00295
00296 bool desynchronize_(bool result = true);
00297 #ifdef BALL_COMPILER_MSVC
00298 HANDLE dirent_;
00299 HANDLE dir_;
00300 #else
00301 DIR* dir_;
00302 dirent* dirent_;
00303 #endif
00304 String directory_path_;
00305 String backup_path_;
00306 };
00307
00308 # ifndef BALL_NO_INLINE_FUNCTIONS
00309 # include <BALL/SYSTEM/directory.iC>
00310 # endif
00311
00312 }
00313
00314 #endif // BALL_SYSTEM_DIRECTORY_H