mirror of https://github.com/kiwix/libkiwix.git
+ add the fileExists() function
This commit is contained in:
parent
400cf57343
commit
5bd84c8db7
|
@ -41,7 +41,7 @@ string computeAbsolutePath(const string libraryPath, const string relativePath)
|
||||||
if (string(token) == "..") {
|
if (string(token) == "..") {
|
||||||
absolutePath = removeLastPathElement(absolutePath, true, false);
|
absolutePath = removeLastPathElement(absolutePath, true, false);
|
||||||
token = strtok(NULL, "/");
|
token = strtok(NULL, "/");
|
||||||
} else if (token != "." && token != "") {
|
} else if (strcmp(token, ".") && strcmp(token, "")) {
|
||||||
absolutePath += string(token);
|
absolutePath += string(token);
|
||||||
token = strtok(NULL, "/");
|
token = strtok(NULL, "/");
|
||||||
if (token != NULL)
|
if (token != NULL)
|
||||||
|
@ -82,3 +82,14 @@ string getFileSizeAsString(const string &path) {
|
||||||
sprintf(csize, "%u", getFileSize(path));
|
sprintf(csize, "%u", getFileSize(path));
|
||||||
return csize;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -20,8 +20,10 @@
|
||||||
#ifndef KIWIX_PATHTOOLS_H
|
#ifndef KIWIX_PATHTOOLS_H
|
||||||
#define KIWIX_PATHTOOLS_H
|
#define KIWIX_PATHTOOLS_H
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -35,5 +37,6 @@ string removeLastPathElement(const string path, const bool removePreSeparator =
|
||||||
const bool removePostSeparator = false);
|
const bool removePostSeparator = false);
|
||||||
unsigned int getFileSize(const string &path);
|
unsigned int getFileSize(const string &path);
|
||||||
string getFileSizeAsString(const string &path);
|
string getFileSizeAsString(const string &path);
|
||||||
|
bool fileExists(const string &path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue