Checking existence of file with boost filesystem to make it more
portable
This commit is contained in:
parent
0e3d2cf68d
commit
b51f98fe0c
@ -21,21 +21,23 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef INPUTFILEUTIL_H_
|
#ifndef INPUTFILEUTIL_H_
|
||||||
#define INPUTFILEUTIL_H_
|
#define INPUTFILEUTIL_H_
|
||||||
|
|
||||||
#include <fstream>
|
#include <boost/filesystem.hpp>
|
||||||
#include <iostream>
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
// Check if file exists and if it can be opened for reading with ifstream an object
|
// Check if file exists and if it can be opened for reading with ifstream an object
|
||||||
bool testDataFile(const char *filename){
|
inline bool testDataFile(const char *filename){
|
||||||
std::ifstream in(filename, std::ios::binary);
|
boost::filesystem::path fileToTest(filename);
|
||||||
if(in.fail()) {
|
if(!boost::filesystem::exists(fileToTest)) {
|
||||||
std::cerr << "[error] Failed to open file " << filename << " for reading." << std::endl;
|
WARN("Failed to open file " << filename << " for reading.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool testDataFiles(int argc, char *argv[]){
|
|
||||||
|
inline bool testDataFiles(int argc, char *argv[]){
|
||||||
for(int i = 0; i < argc; ++i) {
|
for(int i = 0; i < argc; ++i) {
|
||||||
if(testDataFile(argv[i])==false)
|
if(!testDataFile(argv[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user