31 #include "../Exception.h" 32 #include "../encoding/CharEncoding.h" 35 #include <boost/filesystem.hpp> 41 #if TE_PLATFORMCODE_MSWINDOWS == TE_PLATFORM 43 #elif TE_PLATFORMCODE_LINUX == TE_PLATFORM 46 #elif TE_PLATFORMCODE_APPLE == TE_PLATFORM 47 #include <mach-o/dyld.h> 53 boost::filesystem::current_path().
string());
58 std::string complete =
67 boost::filesystem::temp_directory_path().
string());
73 boost::filesystem::unique_path(format).
string());
79 boost::filesystem::absolute(path).
string());
84 return boost::filesystem::extension(path);
89 return boost::filesystem::is_directory(
100 return boost::filesystem::is_regular_file(
106 #if TE_PLATFORMCODE_MSWINDOWS == TE_PLATFORM 108 if(GetModuleFileName(NULL, exePath,
sizeof(exePath)) == 0)
110 #elif TE_PLATFORMCODE_SOLARIS == TE_PLATFORM 111 char exePath[PATH_MAX];
112 if(realpath(getexecname(), exePath) == NULL)
114 #elif TE_PLATFORMCODE_LINUX == TE_PLATFORM 115 char exePath[PATH_MAX];
116 ssize_t len = ::readlink(
"/proc/self/exe", exePath,
sizeof(exePath));
117 if(len == -1 || len ==
sizeof(exePath))
120 #elif TE_PLATFORMCODE_APPLE == TE_PLATFORM 121 char exePath[PATH_MAX];
122 uint32_t len =
sizeof(exePath);
123 if(_NSGetExecutablePath(exePath, &len) != 0)
129 char* canonicalPath = realpath(exePath, NULL);
130 if(canonicalPath != NULL)
132 strncpy(exePath, canonicalPath, len);
138 boost::filesystem::path
p(exePath);
149 return boost::filesystem::create_directory(
155 return boost::filesystem::create_directories(
160 const std::string& to)
172 const std::string& new_p)
179 const std::string& path)
185 std::vector<std::string> result;
189 for(boost::filesystem::directory_iterator it(p), it_end; it != it_end; ++it)
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
static bool isDirectory(const std::string &path)
Checks if a given path in UTF-8 is a directory.
static std::vector< std::string > listDirectory(const std::string &path)
Lists a directory from a given path in UTF-8.
static bool createDirectories(const std::string &path)
Creates a directory for any element of path that does not exist.
static bool isEmpty(const std::string &path)
Checks if a given path in UTF-8 is an empty directory.
static std::string fromUTF8(const std::string &src)
Convert a string in UTF-8 to the current locale encoding.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
static void rename(const std::string &old_p, const std::string &new_p)
Renames a file or directory from a given path in UTF-8.
static std::string extension(const std::string &path)
Retrives the extension of a given file path in UTF-8.
static std::string absolutePath(const std::string &path)
Retrives the absolute path for the given path in UTF-8.
static bool remove(const std::string &path)
Removes a file or directory from a given path in UTF-8.
A class for handling system files and paths.
static std::string uniquePath(const std::string &format="%%%%-%%%%-%%%%-%%%%")
Retrives an unique path generated by a given format.
static void copyFile(const std::string &from, const std::string &to)
Copies a file.
static bool createDirectory(const std::string &path)
Creates a directory from a given path in UTF-8.
static std::string systemCompletePath(const std::string &path)
Composes an absolute path for the given path in UTF-8.
static std::string executableDirectory()
static std::string toUTF8(const std::string &src)
Convert a string from a current locale encoding to UTF-8.
static uintmax_t fileSize(const std::string &path)
Returns the file size of a FILE in UTF-8.
static std::string tempDirectoryPath()
Retrives the temp directory in UTF-8.
static std::string currentPath()
Retrives the current working directory path in UTF-8.
An exception indicating that a given argument is not valid, for instance if a given item already exis...
static bool isRegularFile(const std::string &path)
Checks if a given path in UTF-8 is a regular file.