Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FILE_H
00023 #define FILE_H
00024
00025
00026
00027 #include "utilite/UDirectory.h"
00028 #include <string>
00029
00035 class UFile
00036 {
00037 public:
00043 static bool exists(const std::string &filePath);
00044
00050 static long length(const std::string &filePath);
00051
00057 static int erase(const std::string &filePath);
00058
00065 static int rename(const std::string &oldFilePath,
00066 const std::string &newFilePath);
00067
00073 static std::string getName(const std::string & filePath);
00074
00075 static std::string getExtension(const std::string &filePath);
00076
00077 public:
00082 UFile(const std::string & path) : path_(path) {}
00083 ~UFile() {}
00084
00089 bool isValid() {return exists(path_);}
00090
00095 bool exists() {return exists(path_);}
00096
00101 long length() {return length(path_);}
00102
00107 int rename(const std::string &newName)
00108 {
00109 std::string ext = this->getExtension();
00110 std::string newPath = UDirectory::getDir(path_) + std::string("/") + newName;
00111 if(ext.size())
00112 {
00113 newPath += std::string(".") + getExtension(path_);
00114 }
00115 int result = rename(path_, newPath);
00116 if(result == 0)
00117 {
00118 path_ = newPath;
00119 }
00120 return result;
00121 }
00126 std::string getName() {return getName(path_);}
00131 std::string getExtension() {return getExtension(path_);}
00132
00133 private:
00134 std::string path_;
00135 };
00136
00137 #endif