Check if file exists

This commit is contained in:
Matt McWilliams 2023-02-03 16:15:44 -05:00
parent 40a97baad8
commit 840f6743f9
2 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
mkdir build
mkdir -p build
cd build
cmake ..
make -j

View File

@ -1,8 +1,14 @@
#include <iostream>
#include <opencv2/core.hpp>
#include <sys/stat.h>
using namespace std;
using namespace cv;
inline bool file_exists (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
int main(int argc, char** argv)
{
@ -11,14 +17,19 @@ int main(int argc, char** argv)
if (argc == 2) {
input = argv[1];
} else if (argc < 2) {
cerr << "Please provide one image" << endl;
cerr << "Please provide one image." << endl;
return -1;
} else if (argc > 2) {
cerr << "Please provide only one image" << endl;
cerr << "Please provide only one image." << endl;
return -2;
}
cout << "Using image " << input << endl;
if (!file_exists(input)) {
cerr << "File " << input << " does not exist." << endl;
return -3;
}
cout << "Using image " << input << "." << endl;
return 0;
}