From 5bd84c8db788fb9180f6f19b060593dc2aafb3fe Mon Sep 17 00:00:00 2001 From: kelson42 Date: Fri, 28 Oct 2011 16:13:44 +0000 Subject: [PATCH] + add the fileExists() function --- src/common/pathTools.cpp | 13 ++++++++++++- src/common/pathTools.h | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/common/pathTools.cpp b/src/common/pathTools.cpp index aeee85e4e..fade2d17f 100644 --- a/src/common/pathTools.cpp +++ b/src/common/pathTools.cpp @@ -41,7 +41,7 @@ string computeAbsolutePath(const string libraryPath, const string relativePath) if (string(token) == "..") { absolutePath = removeLastPathElement(absolutePath, true, false); token = strtok(NULL, "/"); - } else if (token != "." && token != "") { + } else if (strcmp(token, ".") && strcmp(token, "")) { absolutePath += string(token); token = strtok(NULL, "/"); if (token != NULL) @@ -82,3 +82,14 @@ string getFileSizeAsString(const string &path) { sprintf(csize, "%u", getFileSize(path)); return csize; } + +bool fileExists(const string &path) { + bool flag = false; + fstream fin; + fin.open(path.c_str(), ios::in); + if (fin.is_open()) { + flag = true; + } + fin.close(); + return flag; +} diff --git a/src/common/pathTools.h b/src/common/pathTools.h index 68c4c7bb6..bf7e9aba0 100644 --- a/src/common/pathTools.h +++ b/src/common/pathTools.h @@ -20,8 +20,10 @@ #ifndef KIWIX_PATHTOOLS_H #define KIWIX_PATHTOOLS_H -#include #include +#include +#include +#include #include #include #include @@ -35,5 +37,6 @@ string removeLastPathElement(const string path, const bool removePreSeparator = const bool removePostSeparator = false); unsigned int getFileSize(const string &path); string getFileSizeAsString(const string &path); +bool fileExists(const string &path); #endif